Form Chooser

rss

Posted by schuess - Oct 29 ’15 at 01:28

I have a simple form that displays a 4 Radio Button Options. I would like to open up a different form based on the selection choosen. This is what i have, but when i test, the script does it does not register the first choice made, it is not until i change my choice when it executes. Do you have a good way to approach this? How do you suggest others accomplish the goal of having a form that shows selections of other forms to choose?

 

//On Change, execute...

fd.field('cosFormType').change(function(){

 

if (fd.field('cosFormType').value() == 1) {

fd.openForm('fd_Contact_Display.aspx');

}else if (fd.field('cosFormType').value() == 2) {

fd.openForm('fd_Contact_Display.aspx');

}else if (fd.field('cosFormType').value() == 3) {

fd.openForm('fd_Contact_Display.aspx');

}else if (fd.field('cosFormType').value() == 4) {

fd.openForm('fd_Contact_Display.aspx');

}

return true;

}) ;

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 11 months 4 days
    #1 by rostislav Oct 30 ’15 at 05:53

    The enumaration of indicies start with 0 - not 1 - in this case. So, change your

    fd.field('cosFormType').value() == 1
    

    to

    fd.field('cosFormType').value() == 0
    

    and the following lines accordingly and it should work.

    Regarding your second question - do you want our recommendation on how to do this? I think your way of doing it is fine. From a user experience point of view though, I'd have a button "Go" that'd transfer the user to the appropriate page (whilst still getting the value from the choice control), instead of having an onchange handler.

  • schuess
    schuess
    Member
    Member for: 6 years 2 months 18 days
    #2 by schuess Oct 30 ’15 at 09:52

    Works great now. Thanks

  • schuess
    schuess
    Member
    Member for: 6 years 2 months 18 days
    #3 by schuess Nov 10 ’15 at 11:19

    What I am seeing now, is that even though i switch forms, which are associated with a new content type, the item is still saved with the original content type of the form chooser form.

     

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 11 months 4 days
    #4 by rostislav Nov 10 ’15 at 11:38

    [#3]:

    To change the content type of an item simply add the Content Type field to your form (found among all the other fields of the list). Whenever the user selects another content type the page is automatically reloaded with the appropriate content-type specific form. You need to save that form in order for the change to take effect.

  • schuess
    schuess
    Member
    Member for: 6 years 2 months 18 days
    #5 by schuess Nov 10 ’15 at 11:54

    Thanks, and that works too. However, is there a way to change content types with code, so that i can still use my Radio Button Form Chooser Option?

  • schuess
    schuess
    Member
    Member for: 6 years 2 months 18 days
    #6 by schuess Nov 10 ’15 at 12:12

    If i could just set the content type value on each new form, or change the content type before i switch forms.

  • schuess
    schuess
    Member
    Member for: 6 years 2 months 18 days
    #7 by schuess Nov 10 ’15 at 01:22

    This worked for me. Look ok?

     

    fd.field('cosFormType').change(function(){

    if (fd.field('cosFormType').value() == 0) {
    contentType.find('option').eq(2).prop('selected', true);
    contentType.change();
    }else if (fd.field('cosFormType').value() == 1) {
    contentType.find('option').eq(3).prop('selected', true);
    contentType.change();
    }else if (fd.field('cosFormType').value() == 2) {
    contentType.find('option').eq(1).prop('selected', true);
    contentType.change();
    }else if (fd.field('cosFormType').value() == 3) {
    contentType.find('option').eq(4).prop('selected', true);
    contentType.change();
    }

    return true;

    }) ;

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 11 months 4 days
    #8 by rostislav Nov 11 ’15 at 05:28

    [#7]:

    I've written the answer to you before I've seen the last message of yours. A nd yes, that's what I wanted to offer you. I'm going to go ahead and post the message anyway, for anyone's reference.

    Regarding your first question: yes, you can. Add the content type field to your form and use the following code to change it:

    // getting the SELECT element
    var contentType = fd.field('ContentType').control()._el().find('select');
    // setting the field to the second type (the 1 means 2nd element, indicies start with 0)
    contentType.find('option').eq(1).prop('selected', true); 
    // reloading the form
    contentType.change();
    

    You can hide the content type field by adding the following line to its style editor in Forms Designer:

    display:none;
    

    Regarding your second question: you can add the content type to any form and do the above with it.

Displaying 1 to 8 of 8 messages