Issue with UI action and Mandatory fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2015 12:37 PM
HI All,
I have a UI action where I am checking for mandatory true for 3 fields and alerting a message when the mandatory field is not filled.
Problem is that it required three clicks for UI action to work since ite checks three times for mandatory.
Is there a way I can achive it in one click?
Please suggest
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2015 01:15 PM
Hey why don't you try creating UI policy for mandatory fields. It will be simple.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2016 08:51 AM
Hi Kavya,
I am guessing you can't use a UI policy for this because you don't necessarily want those fields to be mandatory unless the user clicks the UI Action? ie you want the user to retain the ability to update the record by other means and save it, without having populated those fields.
The way I do this kind of thing is, when the UI Action is clicked, have a client side function that runs first to check if the fields are populated. If one or all of them are not populated, the script sets them mandatory and displays an alert message for the user.
You will need to check the 'Client' box on the UI Action, and fill in the 'Action Name' and 'Onclick' fields. Then use a script something like this one below. For this example, 'Action Name' should be set to doThis, and Onclick set to clicked.
//Client-side 'onclick' function
function clicked(){
var mandToFill = false; //this gets set to TRUE below, if any of the mandatory fields have not been populated.
if(g_form.getValue('u_myField1') == ''){
g_form.setMandatory('u_myField1', true);
mandToFill = true;
}
if(g_form.getValue('u_myField2') == ''){
g_form.setMandatory('u_myField2', true);
mandToFill = true;
}
if(g_form.getValue('u_myField3') == ''){
g_form.setMandatory('u_myField3', true);
mandToFill = true;
}
if (mandToFill){
alert('Please enter a value in myField1, myField 2 and myField3 and then click the button again.');
return true;
}
if(confirm('Are you sure you want to do blah blah blah?') == false){
return false; //Abort submission
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'doThis'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode(){
//DO SOME STUFF HERE
}
I hope this helps.
Jamie.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2016 07:02 AM
HI Jamie,
I have a code something similar to this, problem is this is the alert message wil be displayed one after another, so if there are three fields then the button needs to be clicked three times to display alert for three fields,
Is there a possibility that I can store it in a array and display the alert message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2016 09:22 AM
Hi Kavya,
The code I've shared will only display one alert, so there'll only be one click required. It checks all three fields first, and then displays a single alert if any one of those fields hasn't yet been filled in.
Jamie.