Onsubmit vs onchange function

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

06 Jul 2018

Hi there,
I have a function which works perfectly fine onsubmit:

Code: Select all

fd.onsubmit(function() {
var container = fd.field('Facility').control()._el().find('.ms-taxonomy').get(0);
var taxCtlObj = new Microsoft.SharePoint.Taxonomy.ControlObject(container);
var termValue = taxCtlObj.getRawText();
var str = termValue;
var res = str.substr(0,4)
  fd.field('FacilityCheck').value(res);
  return true
});
I need it to work on change though .... so i tried this:

Code: Select all

function setFC() {
var container = fd.field('Facility').control()._el().find('.ms-taxonomy').get(0);
var taxCtlObj = new Microsoft.SharePoint.Taxonomy.ControlObject(container);
var termValue = taxCtlObj.getRawText();
var str = termValue;
var res = str.substr(0,4)
  fd.field('FacilityCheck').value(res);
}
 
// Calling  when the user changes plant .
fd.field('Facility').change(setFC);
 
// Calling on form loading
setFC();
and the subsring is not passed to the field.... Could you please help me and point out my mistake?

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

09 Jul 2018

Dear Katy,
Please, try to call function like this instead:

Code: Select all

fd.field('Facility').change(function(){
  setFC();
});
Cheers

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

09 Jul 2018

No, this doesn't work either, sorry :-(

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

09 Jul 2018

Dear Katy,
There is no need to be sorry, it's okay :) But it should work technically. There might be only a few reasons why it doesn't:
1) Incorrect InternalName of the field. Instead of 'Facility' it's something else. Please, check this in the designer when you select this field. You can also try:

Code: Select all

fd.field('Facility').change(function(){
  alert('change');
});
2) This type of field doesn't support change event, like Taxonomy, for example, then you need to think of a different way to detect change, like an interval timer. For how to detect change in various fields, please, check out this - https://spform.com/javascript-framework ... eld-values
3) There is an error in the code, in this case you'll get a JS error in the browser's console on each change event.

P.S. Judging by the code it is Taxonomy field, isn't it? In this case the change won't fire, and I recommend using an interval timer instead - https://www.w3schools.com/jsref/met_win_setinterval.asp

Set an interval to about a 1000 or 2000. First, check if there is difference in value. If there is, run the setFC(); function.
Cheers

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

09 Jul 2018

OK, i see..... Thank you Nikita!

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests