Page 1 of 1
Form Chooser
Posted: 29 Oct 2015
by schuess
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;
}) ;
Re: Form Chooser
Posted: 30 Oct 2015
by rostislav
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.
Re: Form Chooser
Posted: 30 Oct 2015
by schuess
Works great now. Thanks
Re: Form Chooser
Posted: 10 Nov 2015
by schuess
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.
Re: Form Chooser
Posted: 10 Nov 2015
by rostislav
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.
Re: Form Chooser
Posted: 10 Nov 2015
by schuess
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?
Re: Form Chooser
Posted: 10 Nov 2015
by schuess
If i could just set the content type value on each new form, or change the content type before i switch forms.
Re: Form Chooser
Posted: 11 Nov 2015
by schuess
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;
}) ;
Re: Form Chooser
Posted: 11 Nov 2015
by rostislav
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.