else if code not executing
Posted: 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;
});
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;
});