else if code not executing

rss

Posted by mcgaafar - Mar 25 ’16 at 10:59

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;

});

 

--

Appreciate your help, thanks.

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 5 months 8 days
    #1 by rostislav Mar 25 ’16 at 11:27

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

    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
    Member
    Member for: 3 years 8 months 26 days
    #2 by mcgaafar Mar 25 ’16 at 11:37

    [#1]: 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://formsdesigner.blogspot.com.eg/2014/07/how-to-conditionally-hide-disable-make.html

  • mcgaafar
    Member
    Member for: 3 years 8 months 26 days
    #3 by mcgaafar Mar 25 ’16 at 11:49

    [#2]: 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!

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 5 months 8 days
    #4 by rostislav Mar 25 ’16 at 12:04

    [#3]:

    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
    Member
    Member for: 3 years 8 months 26 days
    #5 by mcgaafar Mar 25 ’16 at 01:22

    Alright, thanks a lot for your help.

Displaying 1 to 5 of 5 messages