Skip to content

Patch: gppa-select-first-random-choice-on-radio.js #666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
* https://gravitywiz.com/gravity-forms-custom-javascript/
*/

// Update "4" to the the ID of your Radio Button field.
$( 'input[id^=choice_' + GFFORMID + '_4_' )[0].checked = true;
// click vs checked: Click triggers other GPPA Fields to be populated appropriately as well, whereas checked does not trigger further reloads.
// Update "3" to the the ID of your Radio Button field, and keep it as "0" for for the first choice.
// Rename "SelectDefaultRoomType" to something unique.
const SelectDefaultRoomType = document.getElementById('choice_' + GFFORMID + '_3_0'); SelectDefaultRoomType.click();
Comment on lines +9 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// click vs checked: Click triggers other GPPA Fields to be populated appropriately as well, whereas checked does not trigger further reloads.
// Update "3" to the the ID of your Radio Button field, and keep it as "0" for for the first choice.
// Rename "SelectDefaultRoomType" to something unique.
const SelectDefaultRoomType = document.getElementById('choice_' + GFFORMID + '_3_0'); SelectDefaultRoomType.click();
// Update "4" to the the ID of your Radio Button field.
$( 'input[id^=choice_' + GFFORMID + '_4_' )
.prop( 'checked', true )
.trigger( 'change' );

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had to do this though, mention the option as well (not only the field):
$( 'input[id^=choice_' + GFFORMID + '_3_0' ).prop( 'checked', true ).trigger( 'change' );