Form Chooser

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
schuess
Posts: 82
Joined: Wed Jan 22, 2014

29 Oct 2015

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;
}) ;

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

30 Oct 2015

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.

User avatar
schuess
Posts: 82
Joined: Wed Jan 22, 2014

30 Oct 2015

Works great now. Thanks

User avatar
schuess
Posts: 82
Joined: Wed Jan 22, 2014

10 Nov 2015

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.

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

10 Nov 2015

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.

User avatar
schuess
Posts: 82
Joined: Wed Jan 22, 2014

10 Nov 2015

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?

User avatar
schuess
Posts: 82
Joined: Wed Jan 22, 2014

10 Nov 2015

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

User avatar
schuess
Posts: 82
Joined: Wed Jan 22, 2014

11 Nov 2015

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;

}) ;

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

11 Nov 2015

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.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests