This topic is locked

JavaScript drop down menu selection

5/20/2017 4:09:19 PM
PHPRunner General questions
T
Tempus_Erus author

9.7 Build 28765 x64. Bootstrap. Popup window.
I am not sure if there is a bug, but have used old tried and tested code.
Task: quite simply, I want to show the 'date field' if I select 'Schedule date' from a drop down menu.
The code on any selection results in the date field being hidden with no further possible changes upon selection.
I have tried show/hide disabled/enabled and various other configurations of JavaScript <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=24717&image=1&table=forumtopics' class='bbc_emoticon' alt=':blink:' /> , 'I can hide fields' not retrieve data from if statements and I cannot seem to 'process a value from a field' resulting in the if statement not being executed as you would expect - i assume! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=24717&image=2&table=forumtopics' class='bbcemoticon' alt='<<' />
Is this a bug?
Code:
var ctrl = Runner.getControl(pageid, 'Status'); -- get the status field

if(ctrl.getValue() != 'Schedule date') -- not 'schedule date' (as appears in the drop down menu) then

pageObj.hideField('ScheduleDateField'); --hide the date field!!

ctrl.on('change', function(){

if (this.getValue() == 'Schedule a date'){ -- get a value if schedule date

pageObj.showField('ScheduleDateField'); -- show date selection field so calendar can be entered!!

}

else {

pageObj.hideField('ScheduleDateField'); -- if not hide.

}

});

jadachDevClub member 5/20/2017

If it's on the add page, try this:
var ctrlStatus = Runner.getControl(pageid, 'Status');

var ctrlScheduleDateField = Runner.getControl(pageid, 'ScheduleDateField');
pageObj.hideField("ScheduleDateField");
ctrlStatus.on('change', function(e){

if (this.getValue() == 'Schedule date'){

pageObj.showField("ScheduleDateField");

ctrlScheduleDateField.addValidation("IsRequired");

}

else{

pageObj.hideField("ScheduleDateField");

ctrlScheduleDateField.removeValidation("IsRequired");

ctrlScheduleDateField.setValue('');

}

});

T
Tempus_Erus author 5/21/2017



If it's on the add page, try this:
var ctrlStatus = Runner.getControl(pageid, 'Status');

var ctrlScheduleDateField = Runner.getControl(pageid, 'ScheduleDateField');
pageObj.hideField("ScheduleDateField");
ctrlStatus.on('change', function(e){

if (this.getValue() == 'Schedule date'){

pageObj.showField("ScheduleDateField");

ctrlScheduleDateField.addValidation("IsRequired");

}

else{

pageObj.hideField("ScheduleDateField");

ctrlScheduleDateField.removeValidation("IsRequired");

ctrlScheduleDateField.setValue('');

}

});


Thanks for that!
I have tried similar and tried the above and the result is the same. Field is hidden. Its seems I cannot retire a value in order to test accordingly....
at the moment a little stuck on this....

jadachDevClub member 5/21/2017

Not sure what you mean by "cannot retire a value in order to test accordingly"

T
Tempus_Erus author 5/21/2017



Not sure what you mean by "cannot retire a value in order to test accordingly"


lol, retrieve a value. When trouble shooting I have gone right back to basics. Get the value form the field, print it. The work on form there....
I have a couple of other things to try....