disable the choice in drop down
-
- Posts: 9
- Joined: Wed Jun 29, 2016
if I have multiple values of choices and I want to disable some of them based on user log in how can I do that ??
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi May,
Here is the code you can use to hide the second option in the drop-down:
Replace 'DropDown' with the internal name of your field.
And the following line hides the 'Enter Choice #3' option:
Here is the code you can use to hide the second option in the drop-down:
Code: Select all
fd.field('DropDown').control()._el().find('select option:eq(1)').hide()
And the following line hides the 'Enter Choice #3' option:
Code: Select all
fd.field('DropDown').control()._el().find('select option[value="Enter Choice #3"]').hide()
-
- Posts: 9
- Joined: Wed Jun 29, 2016
should it check what is the value of the choice ?? how did you define the choice value
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Not sure that I understood your case - could you describe it in more detail?
The code above hides an option by its index or by a display value. I expected that you know what options you have in the drop-down otherwise how do you want to hide them?
The code above hides an option by its index or by a display value. I expected that you know what options you have in the drop-down otherwise how do you want to hide them?
Hello, I am trying to use the second option with check-box choice and it doesn't work. Could you please check it? I tried to change the field to radio buttons - the same result... I also tried to insert .find('Enter Choice #3') - no luck..
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi Katy,
Here is the code for getting selected options from a multi-choice field:
https://spform.com/javascript-framework ... eld-values
Here is the code for getting selected options from a multi-choice field:
Code: Select all
var checkboxIndex = 2;
fd.field('MultiChoice').control()._el()
.find('input[type="checkbox"]').eq(checkboxIndex)
.is(':checked');
I'm sorry, i think i am missing something... So let's say i have a Colour choice column with check-boxes display and following choices:
Red
Green
Black
Yellow
And i need to hide Red and Black based on the condition X. I thought it would look like this:
function setColour() {
if (fd.field('Condition').value() == 'X') {
fd.field('Colour').control()._el().find('select option[value="Red"]').hide();
fd.field('Colour').control()._el().find('select option[value="Black"]').hide();
}
}
fd.field('Condition').change(setColour);
setColour();
Should it look like this?:
function setColour() {
var checkboxIndex1 = 1;
fd.field('Colour').control()._el()
.find('input[type="checkbox"]').eq(checkboxIndex)
.is(':checked');
var checkboxIndex2 = 3;
fd.field('Colour').control()._el()
.find('input[type="checkbox"]').eq(checkboxIndex)
.is(':checked');
if (fd.field('Condition').value() == 'X') {
fd.field('Colour').control()._el().find(checkboxIndex1).hide();
fd.field('Colour').control()._el().find(checkboxIndex2).hide();
}
}
fd.field('Condition').change(setColour);
setColour();
Red
Green
Black
Yellow
And i need to hide Red and Black based on the condition X. I thought it would look like this:
function setColour() {
if (fd.field('Condition').value() == 'X') {
fd.field('Colour').control()._el().find('select option[value="Red"]').hide();
fd.field('Colour').control()._el().find('select option[value="Black"]').hide();
}
}
fd.field('Condition').change(setColour);
setColour();
Should it look like this?:
function setColour() {
var checkboxIndex1 = 1;
fd.field('Colour').control()._el()
.find('input[type="checkbox"]').eq(checkboxIndex)
.is(':checked');
var checkboxIndex2 = 3;
fd.field('Colour').control()._el()
.find('input[type="checkbox"]').eq(checkboxIndex)
.is(':checked');
if (fd.field('Condition').value() == 'X') {
fd.field('Colour').control()._el().find(checkboxIndex1).hide();
fd.field('Colour').control()._el().find(checkboxIndex2).hide();
}
}
fd.field('Condition').change(setColour);
setColour();
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi,
Please, use the code below to hide the second option:
Just replace '1' with 0-based index of the option you want to hide.
Please, use the code below to hide the second option:
Code: Select all
fd.field('FieldName').control()._el().find('tr:eq(1)').hide();
-
- Information
-
Who is online
Users browsing this forum: No registered users and 3 guests