Page 1 of 1

else if code not executing

Posted: 25 Mar 2016
by mcgaafar
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;
});

Re: else if code not executing

Posted: 25 Mar 2016
by rostislav
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.

Re: else if code not executing

Posted: 25 Mar 2016
by mcgaafar
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

Re: else if code not executing

Posted: 25 Mar 2016
by mcgaafar
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!

Re: else if code not executing

Posted: 25 Mar 2016
by rostislav
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.

Re: else if code not executing

Posted: 25 Mar 2016
by mcgaafar
Alright, thanks a lot for your help.