formatting form fields

Hi Stanislav,

I’m here again with new problems that need your help.

  1. A strange behaviour in formatting form fields:

I’ve some numeric fields that i defined as DOUBLE in Mysql DB and i edit them in a form whose structure is defined in xml file. The problem is numberFormat.
If i use this definition:

numberFormat=“0,000.00” groupSep="." decSep=","

all runs correctly. The numbers are shown in this way 1.230,00 and are correctly stored to DB. As this fields must contain only integer numbers i want to avoid to show the decimals so i tried to modify the definition in this way:

numberFormat=“0,000” groupSep="." decSep=","

The result is that if i write 1000 in the fields, saving the form, the number become 1 loosing the zeroes and the same happens in the DB. I thought it could depend on the number definition in the DB so i change it from DOUBLE to MEDIUMINT, but the problem remains exactly the same.

What’s wrong ! Can you Help me ?

  1. I know that in the XML definition of a Form is possible to Align the labels, but is it possible align also the fields (ie numeric fields aligned to the right) ?

  2. Is it possible in forms to use formulas as in grid, building a calculated fields binded to the DB ?

As always many thank for your patient.

Hi Stanislav,

Sorry i’ve to correct my previous post as regard the numberFormat
with this definition

numberFormat=“0,000” groupSep"." decSep="," writing an integer number like 4535, saving the form the number become 4 and in the DB is stored as a decimal number 4.535 (. as decimal point)

I cannot understand.

Hi Stanislav,

Did you disappeared or did you get tired of me ?

I’ve always the problem to avoid decimals in form fields (as in my previous post) but now i’ve also another problem.

I read in the forum that setDateFormat is valid only for dhxCalendar cells in a grid, but is possibile to use a ‘ro’ cell formatting in the correct way the date on server side. Would this mean to format the date in my PHP script that contains render_table or render_sql to retrieve data from MYsql and that i use in load event of grid ?.

What is the correct syntax to use in these calls (render_table and render_sql) to format dates ?

Many thanks as always !

Hi

sorry, seems like we missed your 7-feb’s message

  1. if problem with formattnig values in a form still actual - please provide completed demo where we can reproduce issue localy. we already have some fixes in this functionality based on forum’s questions, maybe your already solved. if not I will provide a fix

  2. align in inputs not supported. you can after form loaded - myForm.getInput(name).style.textAlign = “right”; also you can pass corresponding fields in userdata, i.e. process will automated

  3. natively form does not provide such functionality. there is a field “template” - it have format function, so you can add some calculations

I will say hello to Stanislav :wink:

Thanks Andrei but you forget the last question:

The problem related to format DATE in a ‘ro’ grid. !

I believe it’s not truth that align in input is not supported.

i used this syntax in xml definition of form:

<item type =“input” name=“IAC” bind=“IAC” numberFormat=0,000.00" groupsSep="." decSep="," style=“text-aling:right”/>

and it runs correctly for aligning but i continue to have problem with decimals in the way that i explained in my previous posts.

Hi

  1. regarding grid you need to push Stanislav

  2. regarding form p.1 - as I already told - please provide completed demo

  3. style=“text-aling:right” doing the same but on init stage, also good solution

Hi

I’ve another question.

i read in the forum that the actual version doesn’t support onblur and onfocus events in forms and probably the suite will support them in the next version !

In the while, Is there a way to intercept them through dhtmlxEvent or something else ?

Thanks

Hi

you can try by using:

var inp = myForm.getInput("name"); if (window.addEventListener) { inp.addEventListener("focus", function(){}, false); } else { inp.attachEvent("onfocus", function(){}); }

the same for onBlur. do not use inp.onfocus or inp.onblur - this can override default logic. if you have active support you can open ticket in support and we will provide version which will officialy support onFocus/onBlur

I cannot open the Ticket cause i’ve simply the standard version of the suite. If it was possible to have the patch the same it would be fantastic.

Anyway, i built a function that scan the elements of the form to attach the event in the same way that you indicated.
I put the call to this function in the window onload event after having loaded the form structure from xml.
When i scan the document, the result of document.forms.lenght is always 0, even if the call is after form.loadStruct.

Where is the problem ?

Many many thanks. I’ll never finish to thank for your patient.

Hi

xml loads into form in async mode, and probably when you try to get input, it not yet loaded. so you need something like this:

myForm.loadStruc(“form_struct.xml”, function(){
// callback, here form loaded 100%
// your code here
});

Hi Andrei,

i followed your suggestion but the document.forms.lenght returns always 0. It seems that forms loaded from xml is not recognized as forms.

This is my code:

contactForm.loadStruct("xml/form_iter.xml, function() {
alert(“form loaded”);
setListner(“focus”, setBKColor);
setListner(“blur”, resetBKColor);
});

the function setListner is my function where i scan the form to attach the events to the element. Inside this function i test the presence of the form with document.forms.lenght that continue to return 0.

Where is the error ?

Thanks.

dhtmlxForm isn’t DOM form element. you will not able to do such operations.

So isn’t there any other way to intercept onFocus and onBlur for standard version User ? :wink:

Any suggestion ?
Thanks

Another problem !

i’m trying to build the same function i told before not using DOM but using dhtmlx api (getForm, getInput and getItemList)

I’ve a form that contains some fieldsets with included inputs and combos. If i try to loop through the list: item[1]) i find only the fieldsets. How should i refer to the sub-items ?
item[1,1]
item[1],[1]
or something else ?

Thanks again.

Hi

  1. regarding onFocus/Blur
    as I already told - use myForm.getInput(name).addEventListener()

  2. du complex form struct there is no dirrect common possibility to get item like you try. use form’s functionality, check our doc for details

Many Thanks,

I reach the result. I built general function to attach events to form items using getInput, forEachItem etc. the Api a the end !

But now i return on an old problem that i didn’t solve yet. I think that there could be a bug in setNumberFormat when the dot “.” is used as group separator instead of as decimal separator

this is my sintax:

contactForm.setNumberFormat(“IAC”,“0,000”,"."); to have 1350 as 1.350

in this case the function truncate the last 3 numbers and show number 1 that is also stored in the DB in the same way.

if i modify the group separator:
contactForm.setNumberFormat(“IAC”,“0,000”,"’"); to have 1350 as 1’350

the number is correctly shown (1’350) and stored in db as 1350.

it seem to be a bug ! doesn’t it ?

Another problem:
I’d like to navigate between form fields using Enter instead of TAB. Is there an easy way to obtain or it’s necessary catch “onEnter” and the to use some kind of “Sendkey”.

Hi

in both cases original value should be 1350
but in form w/o focus should be 1.350 and 1’350

we will add fix for future version (it will soon) or you can attach your demo including all corresponding js/css files and I will add fix directly into your form version

hi everybody,

Well i’ll provide the files for the upgrade, but now another problem happened.

I’m building a form with 3 numeric fields, 1 date field e some other text fields.

No problem with text fields but with numeric and date fields i’ve this unsolvable problem.

When i saved the form, if one of the numeric field or date field is empty, in the db (Mysql) through my PHP Script, 0 instead of null are saved. I want NULL instead, so reading the record again shows empty fields on the form and not zeroes or strange date based on 0000-00-00.
Of course the DB are null enabled.

After a long surfing on the net i found this suggestion:

Don’t use quotes if you want to insert NULL values. Instead write:

values ($col1, $col2, $col3 …

Then add quotes to variables that have a value and set all other to be
“NULL”:

if ($col1) {
$col1 = “’” . mysql_escape_string($col1) . “’”;
} else {
$col1 = “NULL”; // in the SQL query “NULL” will NOT be quoted
}

This means that is necessary to change the php script that write to the db.

I’m using dhtmlxConnector with render_table ! How can i transfer this solution to this function or eventually to render_sql ?

Please help me. I’m in crise

In case of connector, you can use beforeProcessing event with logic like

if ($data->get_value($step["name"]) == "") $step_value = Null;

As result it will be saved as Null in database

Hi Stanislav ! welcome back to help us, poor ignorant programmers

Great suggestion your last one, i finally solved the problem.

Now i’m trying to implement multi-sync . I followed the documentation examples but nothing seems to happen. I set:
dp.setAutoUpdate(2000) immediately after dp.init(MyForm) on client

and set: $formconn->enable_live_update(‘actions_table’); in my PHP and of course i created the actions_table in mysql as specified in the documentation.

I also controled this table and when i save the form the record are populated.

I expected that positioning two different computers in the local lan on the same record, then modifying something on the first one i would have had an alert box, during the save on the second computer, to inform that data has changed. Instead nothing happens.
First computer saves modification to the record and the second can freely modify the record again without any alert.

Where’ s the problem ? I made some errors or what i expected from this functionality is not what it does really ?

Many thanks as always.