disable the choice in drop down

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
May.AlFarsi
Posts: 9
Joined: Wed Jun 29, 2016

18 Apr 2017

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 ??

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

18 Apr 2017

Hi May,
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()
Replace 'DropDown' with the internal name of your field.

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()

May.AlFarsi
Posts: 9
Joined: Wed Jun 29, 2016

19 Apr 2017

should it check what is the value of the choice ?? how did you define the choice value

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

20 Apr 2017

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?

Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

23 Jun 2017

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..

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

26 Jun 2017

Hi Katy,
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');
https://spform.com/javascript-framework ... eld-values

Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

26 Jun 2017

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();

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

27 Jun 2017

Hi,
Please, use the code below to hide the second option:

Code: Select all

fd.field('FieldName').control()._el().find('tr:eq(1)').hide();
Just replace '1' with 0-based index of the option you want to hide.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests