Set/Remove "read-only" status for form fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 07:26 AM
As per my requirements I need to open existing record and disable (set "read-only" to true) all form fields.
Also there should be a button on a form which will enable (set "read-only" to false) all form fields.
I did the following:
1. Created client script that disable existing record: Gyazo - 49fb5bd9c0765865b27e304a7acd5343.png - it works fine
2. Created form button and add action: Gyazo - f1247f0b2aa73bdc99d201080434aff7.png - but it doesn't work: when I click this button - nothing happens - but it will enable all form fields for editing
Please advice where I am wrong?
Debugger doesn't stop in onClick() function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 10:34 AM
Hi,
Both of the Requirements are contradictory I Guess because with the help of a on Load Client Script we are making the fields as Read Only and then again when we are configuring the UI Action to make the field Editable again, say the UI Action made it Editable again but since we already have an On Load Client Script it will again make the form as Read Only.
The Solution for this will be either create Two Separate UI Action on the form one for making the fields Read Only and the other for making it Editable again Or We can create a custom field on the form say a Check Box Type field which will act like a Flag for controlling Form Validations.
This can be done as per the steps mentioned below:
We have created a Custom field "Read Only Flag" on the Problem Form.
1) For your first Requirement:
For Example I want to make all fields as Read only on the Problem Form so we need to write an On Change Client Script on the Problem Table on Read Only Flag field we created as shown below:
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
if(g_form.getValue('u_read_only_flag')=='true')
{
var fields1 = g_form.getEditableFields();
for (var x1 = 0; x1 < fields1.length; x1++) {
if(fields1[x1]=='u_read_only_flag')
continue;
g_form.setReadOnly(fields1[x1], true);
}
}
return;
}
if(newValue=='true')
{
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
if(fields[x]=='u_read_only_flag')
continue;
g_form.setReadOnly(fields[x], true);
}
}
//Type appropriate comment here, and begin script below
}
Result:
All fields Become Read Only as shown below except "Read Only Flag" Field
2) For your Second Requirement, as per your need you can configure a UI Action to make fields Editable again and setting the Value of the Flag "Read Only Flag" field as False again so that it does not contradict with our on Change Client Script as shown below:
Ui Action Script:
function prob_edit(){
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], false);
}
gsftSubmit(null, g_form.getFormElement(), 'field_edit'); //MUST call the 'Action name' set in this UI Action
}
if (typeof window == 'undefined')
problem_edit();
function problem_edit(){
current.u_read_only_flag='false';
current.update();
action.setRedirectURL(current);
}
Result:
Hope this helps.Mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2017 07:59 AM
Thanks Shloke,
In my example there is a client script (fires on form onLoad) which set readonly all fields:
https://gyazo.com/8058c975de7776ac66b7e9fa9449e497
And in my UI action I added "Edit" button and add action by onClick:
Gyazo - 1bdfc772b3b42b78a250af29a3ce416a.png
I would like to know why form reloads to new one when I click to "Edit" button?
But again: it works as per your example - thanks.
Last question in this thread: how to do the following requirement: I need to open existing record in a form and will have all fields read-only - that is why I added onLoad script
I don't need to have an additional checkbox in a form. Or in other words - how to click this checkbox (Read Only Flag) programmatically?
So main question here: is it possible to setReadonly to false (enable editing) WITHOUT reloading form?
Thanks