Page 1 of 1

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

Posted: 14 Nov 2017
by Oz.Ab
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?

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

Posted: 14 Nov 2017
by Nikita Kurguzov
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.

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

Posted: 14 Nov 2017
by Oz.Ab
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').....?

:)

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

Posted: 17 Nov 2017
by Oz.Ab
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').....?

:)

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

Posted: 18 Nov 2017
by Nikita Kurguzov
Hello, Oz!
Try this code:

Code: Select all

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

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

Posted: 21 Nov 2017
by Oz.Ab
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.

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

Posted: 21 Nov 2017
by Oz.Ab
Sorry Nikita - my mistake.

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

All the best.