Toggle read-only
-
- Posts: 4
- Joined: Wed Jun 24, 2015
I have a form with a People Picker field called Participants, on the Edit Form I would like to keep this field read-only because I have People Picker configured to show Picture and Name, and having the person's picture is important to the process.
This all works fine when i set People Picker to read-only in properties, but I would also like the user to be able to open the People Picker field to add people if desired, and I would like to do this with a button, so when you click the button if the field is read-only = true it will switch to read-only= False and vice versa.
Following the example of how to dynamically disable / enable fields , I have been going through the iterations putting code OnClick like
If fd.field('Participants').readonly(true){
fd.field('Participants').readonly(false);
} else {
fd.field('Participants').readonly(true);
}
No matter what I do, i cannot get the field to toggle back and forth from read-only TRUE / FALSE.
Is this not possible?
This all works fine when i set People Picker to read-only in properties, but I would also like the user to be able to open the People Picker field to add people if desired, and I would like to do this with a button, so when you click the button if the field is read-only = true it will switch to read-only= False and vice versa.
Following the example of how to dynamically disable / enable fields , I have been going through the iterations putting code OnClick like
If fd.field('Participants').readonly(true){
fd.field('Participants').readonly(false);
} else {
fd.field('Participants').readonly(true);
}
No matter what I do, i cannot get the field to toggle back and forth from read-only TRUE / FALSE.
Is this not possible?
Please use the following code:
Code: Select all
fd.field('Participants').readonly((fd.field('Participants').readonly() == true) ? false :
-
- Posts: 4
- Joined: Wed Jun 24, 2015
The button does not appear to be firing. I added a button to the form and put the following code OnClick:
alert('OK');
If fd.field('Participants').readonly(true){
fd.field('Participants').readonly((fd.field('Participants').readonly() == false);
} else {
fd.field('Participants').readonly((fd.field('Participants').readonly() == true);
}
It is not even firing the alert..
alert('OK');
If fd.field('Participants').readonly(true){
fd.field('Participants').readonly((fd.field('Participants').readonly() == false);
} else {
fd.field('Participants').readonly((fd.field('Participants').readonly() == true);
}
It is not even firing the alert..
-
- Posts: 4
- Joined: Wed Jun 24, 2015
I have played around a little with setting fields read-only = False for a couple of other non-People Picker fields, and these are plain text fields ...
I tried the On click event a couple of different ways
fd.field('Questions').readonly(false);
or
fd.Field('Questions').readonly((fd.Field('Questions').readonly() == false);
or
fd.Field('Questions').readonly() == false;
In all cases there is no effect on the Questions field on the form. Nothing is happening.
My syntax is sound according to dynamic form examples provided in the article as well as feedback provided here. I still cannot understand why i cannot manually "open" a field for editing with apparently well formed JS
I tried the On click event a couple of different ways
fd.field('Questions').readonly(false);
or
fd.Field('Questions').readonly((fd.Field('Questions').readonly() == false);
or
fd.Field('Questions').readonly() == false;
In all cases there is no effect on the Questions field on the form. Nothing is happening.
My syntax is sound according to dynamic form examples provided in the article as well as feedback provided here. I still cannot understand why i cannot manually "open" a field for editing with apparently well formed JS
Regarding your second post: No, your syntax is not correct, that is why your code isn't being executed. To see what's wrong with it you can open console in the web browser (in Chrome it is F12) and open the console tab. Once you click your button any errors will be output there. In case with your code in the second post it is synctatically incorrect, there is no identifier 'If', it is 'if', there are places where brackets are missing, there are places where there are additional brackets and all of this causes errors. If you want a synctatically correct version of your code:
I'm not sure what you're trying to do with it though. If you want to achieve what you described in your first post - use the code I posted above. Regarding you third post:
will make the Questions field *not* readonly, if you want to make it readonly you have to pass true, not false, i.e.
there is no 'Field' identifier, it is 'field' same goes for
Anyway, again, if you want to achieve what you described initially, remove all synctatically incorrect code from the onclick property and use the code we posted before. Also, if you want to experiment with javascript, you can do it interactively in the console, the way I described above.
Code: Select all
if (fd.field('PeoplePicker').readonly(true)){
fd.field('PeoplePicker').readonly(fd.field('PeoplePicker').readonly() == false);
} else {
fd.field('PeoplePicker').readonly(fd.field('PeoplePicker').readonly() == true);
}
Code: Select all
fd.field('Questions').readonly(false);
Code: Select all
fd.field('Questions').readonly(true);
fd.Field('Questions').readonly((fd.Field('Questions').readonly() == false);
Code: Select all
fd.Field('Questions').readonly() == false;
-
- Information
-
Who is online
Users browsing this forum: No registered users and 32 guests