On change doesn't work with "Specify your own value"

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Oz.Ab
Posts: 39
Joined: Mon Oct 09, 2017

14 Nov 2017

Hi,

I have a choice field that allows you to add your own value ("Specify your own value").

When this choice field changes a function is triggered that gets the value (used in a variable in the function). This works fine when choosing from the dropdown list. So if the:
- user selects ABC in 'MA'
- user selects 123 in 'ChoiceField'
= then 'MAcode' will be ABC123

But the function doesn't trigger when the user fills the field under "Specify your own value". So when the user does not use the dropdown list, but fills the "specify your own value" field, the function doesn't work:
- user selects ABC in 'MA'
- user writes 333 in "Specify your own value" in the 'ChoiceField'
= then 'MAcode' will be ABC but it should be ABC333

The choice field internal name is ChoiceField.
This is how my function is:

function setMAcode() {
var mText = fd.field('MA')control('getSelectedText');
var mNumber = fd.field('ChoiceField').value();
var combined = mText + mNumber;
fd.field('MAcode').value(combined);
}
fd.field('ChoiceField').change(setMAcode);

How can my function pick up the information from the "specify your own value" field?

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

14 Nov 2017

Hello, Oz!
You can detect change in the custom input with this code:

Code: Select all

fd.field('ChoiceField').control()._el().find('input').change(function(){
  alert("Field changed!");
});
I also recommend switching this code:

Code: Select all

fd.field('ChoiceField').change(setMAcode);
to this:

Code: Select all

fd.field('ChoiceField').change(function(){
  setMAcode();
});
It should work better.
Cheers

Oz.Ab
Posts: 39
Joined: Mon Oct 09, 2017

14 Nov 2017

Thanks Nikita.

Just one thing - how can I get the value from the "specify your own value" field?

var MAspecify = fd.field('ChoiceField').control()._el().find('input').....?

:)

Oz.Ab
Posts: 39
Joined: Mon Oct 09, 2017

17 Nov 2017

Thanks Nikita.

Just one thing - how can I get the value from the "specify your own value" field?

var MAspecify = fd.field('ChoiceField').control()._el().find('input').....?

:)

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

18 Nov 2017

Hello, Oz!
Try this code:

Code: Select all

fd.field('ChoiceField').control()._el().find('input[type=text]').val();
Cheers

Oz.Ab
Posts: 39
Joined: Mon Oct 09, 2017

21 Nov 2017

Hi Nikita.

As you can see on the screenshot attached my variable isn't getting the XXX from the "specify your own value" field. My variable only gets [object Object]. This results in the field below not updating to "AFXXX", it is just "AFPending" as I chose from the dropdown menu.

I set the variable exactly like you mentioned, but it only gives me [object Object]:

var MAspecify = fd.field(''ChoiceField').control()._el().find('input[type=text]').val();

All assistance highly appreciated.

All the best.
Attachments
SKU pic.jpg
SKU pic.jpg (20.42 KiB) Viewed 1654 times

Oz.Ab
Posts: 39
Joined: Mon Oct 09, 2017

21 Nov 2017

Sorry Nikita - my mistake.

My browser wasn't updating (even though I hit ctrl+f5) your code works fine :)

All the best.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 18 guests