- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2016 04:21 AM
Looking to modify some work that has been done here to make the user experience a little better.
Firstly, on this record we want the user to be able to Save the record with no checks. If the user Submits, then we check for specific fields to be filled in.
The way it has been done via UI Actions works, but when the user submits there are no mandatory field markers and this is what needs addressing.
OK, create a client script and set the fields to be mandatory - easy ? yeah ? - Nope.
I have the following Client Script that checks for the action name, sets a boolean field marker to be true / false and then using an array, loop through all the fields that need checking. - the array has been truncated and some debugging added
function onSubmit() {
var action = g_form.getActionName();
g_form.addInfoMessage(action);
var bolMand = false;
if (action == 'submit_tpip')
bolMand = true;
var arrFields = ['u_project_manager','u_engineer'];
g_form.addInfoMessage(arrFields.length)
for (i=0;i<arrFields.length;i++)
{
g_form.addInfoMessage(arrFields[i] + ' : ' + i);
g_form.setMandatory(arrFields[i], bolMand);
if(i == arrFields.length-1)
g_form.addInfoMessage('Breaking');
}
when I click on save, I see this
which is fine
when I click on Submit, I see this......
So, Why does it do the first field correctly and get suck on the second ?
Why is it not even reaching the if statement to show the "Breaking" info message ?
It is not the field as it is happening on whatever subset of the array I am chosing, and in this screenshot I have just reversed the two fields from the previous code
Ontop of that, I did try using true instead of bolMand and it gives the same problem
Bizzarely, the following code works so it is clearly to do with this running in a loop
g_form.setMandatory('u_engineer',bolMand);
g_form.setMandatory('u_project_manager',bolMand);
g_form.addInfoMessage('and here I am');
any ideas or thoughts ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2016 09:20 AM
Hi Julian,
Could there possibly be a scoping issue with your variable 'i' you are using for your loop that may be causing the unexpected behavior?
You may try changing your for statement to:
for (var i=0;i<arrFields.length;i++)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2016 06:04 AM
was going through this process again today and again it is failing on the loop.
Now doing it in Chrome as well as FF
The routine now does have an try / catch and the catch is not being triggered at all and the two fields it has processed are correct.
Pity as it is a going to be a pain to put in place and ideally I would want to read the "mandatory" fields from a data source so if the team change their minds it is just a data modification and not a change of a script with the resulting change request needed.
However, the users of this particular section have some really odd requests so this idea is now moot anyway - hey ho
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2016 07:56 AM
I'll comment, that while adding try catch has it's places, I would actually suggest against it in most cases for DOM manipulation. When you do the next feature upgrade, the errors generated on the page if the DOM has changed is a dead give-away that you need to make a correction, where if the errors are caught, testers might miss that the page is not working as designed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2016 09:20 AM
Hi Julian,
Could there possibly be a scoping issue with your variable 'i' you are using for your loop that may be causing the unexpected behavior?
You may try changing your for statement to:
for (var i=0;i<arrFields.length;i++)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2016 01:01 PM
I'll look at this properly over the weekend when dig that bit of code out
A quick check via an onLoad and that seems to work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2016 09:56 AM
Not going to change the code just yet as what is there is working - it can wait, but on another dev instance I tried changing the code and it seems to run quite nicely.