else if code not executing

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
mcgaafar
Posts: 44
Joined: Sun Jan 17, 2016

25 Mar 2016

Hi,

I'm using the following code on my edit form, however the else if code is not working, i wonder if anything's wrong (The field QuoteRef is placed on my edit form as read only):

function setFields() {
if (fd.field('Stage').value()=='Closed Won'){
fd.field('GP').titleRequired(true);
fd.field('Title').readonly(true);
fd.field('ProjectReference').readonly(true);
fd.field('Client').readonly(true);
fd.field('LOB').readonly(true);
fd.field('Application').readonly(true);

}

else if (fd.field('Stage').value()=='Closed Lost') {
fd.field('GP').titleRequired(false);
fd.field('Title').readonly(false);
fd.field('ProjectReference').readonly(false);
fd.field('Client').readonly(false);
fd.field('LOB').readonly(false);
fd.field('Application').readonly(false);

}

else {
var quotes = fd.field('QuoteRef').control()._el().text();
fd.field('GP').titleRequired(false);
if (quotes.replace(/\s/g,"") == "") {
fd.field('Title').readonly(false);
fd.field('ProjectReference').readonly(false);
fd.field('Client').readonly(false);
fd.field('LOB').readonly(false);
fd.field('Application').readonly(false);
}
else {
fd.field('Title').readonly(true);
fd.field('ProjectReference').readonly(true);
fd.field('Client').readonly(true);
fd.field('LOB').readonly(true);
fd.field('Application').readonly(true);
}
}
}

// Calling setFields when the user changes the stage
fd.field('Stage').change(setFields);

// Calling setFields on form loading
setFields();

// Custom validation
fd.onsubmit(function () {
if (fd.field('Stage').value()=='Closed Won' && !fd.field('GP').value()){
alert('Please, fill in the GP field.');
return false;
}
return true;
});

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

25 Mar 2016

What constitutes as 'not working'? Why are you retrieving QuoteRef this way? Try

Code: Select all

fd.field('QuoteRef').value()
In any case, use 'debugger;' with opened console (F12) to debug your code - insert

dubugger;
where you want to want the interpreter to break and then execute your code line by line to identify the source of your problem. What is titleRequired in fd.field('GP').titleRequired(false) ? Forms Designer doesn't have this function.

mcgaafar
Posts: 44
Joined: Sun Jan 17, 2016

25 Mar 2016

well for the QuoteRef field i'm using this method as i mentioned in my post i'm placing this field on my form as "Read Only", and when i tried to use the fd.field('QuoteRef').value() it didn't work out.

As for the titleRequired, actually i got it from your forum, it only places an asterisk beside a field, please refer to this link:

http://spform.com/office-365/cond ... ynamically

mcgaafar
Posts: 44
Joined: Sun Jan 17, 2016

25 Mar 2016

What's not working is the code inside the "else if", the fields that should be set as readonly are not set, although the rest of the code is working!

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

25 Mar 2016

Look at the execution path your code is taking. As I have said above, insert 'debugger;' to, e.g., the beginning of setFields, open your console, refresh the page and see what's actually hapenning.

mcgaafar
Posts: 44
Joined: Sun Jan 17, 2016

25 Mar 2016

Alright, thanks a lot for your help.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 13 guests