This topic is locked
[SOLVED]

 JavaSript on datefield

8/1/2010 3:29:12 AM
PHPRunner General questions
J
jdu001 author

Hello,
PHPRunner 5.2 build 5482. Browser is firefox (3.5.7)
I have a datefield on an Add/Edit page.

On the event editor I have assigned a 'Simple edit box with datepicker' to this datefield and the dateformat is Dutch (DD-MM-YYYY).
I want to make this date in the right format if it isn't entered in the right format. (01042010 ==> 01-04-2010)

I made a JavaScript in the JavaScript on load event using the instructions:
-----------------------------------------------------------------------

var ctrlKoopdatum = Runner.getControl(pageid, 'Koopdatum');
function maakDatumOp() {

var datum = ctrlKoopdatum.getValue();

alert(ctrlKoopdatum.getValue());

if (datum.length == 8) {

datum = datum.substr(0,2) + "-" + datum.substr(2,2) + "-" + datum.substr(4,4);

ctrlKoopdatum.setValue(datum);

}

ctrlKoopdatum.setValue(datum);

};
ctrlKoopdatum.on('onchange', maakDatumOp);

-----------------------------------------------------------------------
The alert is to check the value of the date. If I change this date, the date becomes empty. The result of the method ctrlKoopdatum.getValue() is empty.
When I look with firebug I see that there already is a JavaScript on Koopdatum: the datepicker
Is it possible to create my own JavScript on Koopdatum or must I do it in another way?
Greetings,
Jo van Duin

A
ann 8/2/2010

Jo,
you can add the code to the JavaScript Onload Event on the Events tab.

Just modify the following line:

ctrlKoopdatum.on('change', maakDatumOp);
J
jdu001 author 8/3/2010

Hello,
This doesn't help. The value of ctrlKoopdatum.getValue() is FALSE.
Because this field is a datefield, the method getValue() from the subclass DateTextField (from DateFieldControl.js) overrides the method getValue;
This overridden method uses a dateformat. Is it possible to alter this dateformat before calling the getValue() method?
Greetings,
Jo

A
ann 8/5/2010

Jo,
try the following code:

function maakDatumOp() {

var datum = document.forms.editform1.value_Koopdatum_1.value;

if (datum.length == 8) {

datum = datum.substr(0,2) + "-" + datum.substr(2,2) + "-" + datum.substr(4,4);

document.forms.editform1.value_Koopdatum_1.value=datum;

}

};
ctrlKoopdatum.on('click', maakDatumOp);
J
jdu001 author 8/6/2010



Jo,
try the following code:

function maakDatumOp() {

var datum = document.forms.editform1.value_Koopdatum_1.value;

if (datum.length == 8) {

datum = datum.substr(0,2) + "-" + datum.substr(2,2) + "-" + datum.substr(4,4);

document.forms.editform1.value_Koopdatum_1.value=datum;

}

};
ctrlKoopdatum.on('click', maakDatumOp);



Hello Ann,
Thank you very much. This works.

I used 'blur' instead of 'click' so the conversion takes place after leaving the field and not by entering the field.
Best regards,
Jo van Duin