получить значение нажатой кнопки внутри формы

#javascript #jquery #wordpress #safari #gravity-forms-plugin

Вопрос:

Я использую плагин под названием Gravity Forms на своем сайте и добавляю некоторые пользовательские проверки JS, которые отлично работают в firefox/chrome, но у меня возникают проблемы с Safari

На каждой странице есть Следующая и предыдущая, мне нужно выполнить некоторые проверки только при нажатии кнопки «Далее«.У меня есть событие, вызываемое при отправке формы, в котором я проверяю значение нажатой кнопки, а затем добавляю в формы некоторые пользовательские проверки. позвольте мне показать вам мой код.

JS

 jQuery(window).on("load", function() {  jQuery("#gform_1").on("submit", function(e) {  if (jQuery("#gform_page_1_2").is(":visible")) {  if (jQuery(this).find("input[type=button]:focus").val() == "Next") { //creating issue  // some validation logic dont need to worry about that.  }  }  }); });  

HTML

 lt;div id="gform_page_1_2" class="gform_page"gt;  lt;div class="gform_page_fields"gt;  lt;div id="gform_fields_1_2" class="gform_fields top_label form_sublabel_below description_above"gt;  lt;div id="field_1_77" class="gfield gfield_html gfield_html_formatted gfield_no_follows_desc field_sublabel_below field_description_above gfield_visibility_visible"gt;  lt;h2gt;Tell us about your familylt;/h2gt;  lt;/divgt;  lt;fieldset id="field_1_93" class="gfield switch-field gfield_contains_required field_sublabel_below field_description_above gfield_visibility_visible"gt;  lt;legend class="gfield_label"gt;Do you have children?lt;span class="gfield_required"gt;lt;span class="gfield_required gfield_required_text"gt;(Required)lt;/spangt;lt;/spangt;lt;/legendgt;  lt;div class="ginput_container ginput_container_radio"gt;  lt;div class="gfield_radio" id="input_1_93"gt;  lt;div class="gchoice gchoice_1_93_0"gt;  lt;input class="gfield-choice-input" name="input_93" type="radio" value="Yes" checked="checked" id="choice_1_93_0" onchange="gformToggleRadioOther( this )"gt;  lt;label for="choice_1_93_0" id="label_1_93_0"gt;Yeslt;/labelgt;  lt;/divgt;  lt;div class="gchoice gchoice_1_93_1"gt;  lt;input class="gfield-choice-input" name="input_93" type="radio" value="No" id="choice_1_93_1" onchange="gformToggleRadioOther( this )"gt;  lt;label for="choice_1_93_1" id="label_1_93_1"gt;Nolt;/labelgt;  lt;/divgt;  lt;/divgt;  lt;/divgt;  lt;/fieldsetgt;  lt;div id="field_1_283" class="gfield gfield_html gfield_html_formatted gfield_no_follows_desc field_sublabel_below field_description_above gfield_visibility_visible"gt;  lt;h2gt;Children Informationlt;/h2gt;  lt;/divgt;  lt;fieldset id="field_1_7" class="gfield field_sublabel_below field_description_above gfield_visibility_visible"gt;  lt;legend class="gfield_label gfield_label_before_complex"gt;Childrenlt;/legendgt;  lt;div class="gfield_description" id="gfield_description_1_7"gt;Enter all children to be provided for under your Will whether by birth or adoption (you can include stepchildren but only if you want to treat them as a natural or adopted child for inheritance purposes). It is also important to complete the “Relationship” field for each child listed. NOTE: If you selected to plan for both you and your spouse joint children will need to be listed twice: (i) for you and (ii) for your spouse.lt;/divgt;  lt;div class="ginput_container ginput_container_list ginput_list"gt;  lt;div class="gfield_list gfield_list_container"gt;  lt;div class="gfield_list_header"gt;  lt;div class="gfield_header_item"gt;First Namelt;/divgt;  lt;div class="gfield_header_item"gt;Middle Namelt;/divgt;  lt;div class="gfield_header_item"gt;Last Namelt;/divgt;  lt;div class="gfield_header_item"gt;Date of Birth (MM/DD/YY)lt;/divgt;  lt;div class="gfield_header_item"gt;Relationshiplt;/divgt;  lt;div class="gfield_header_item"gt;Special Needslt;/divgt;  lt;div class="gfield_header_item gfield_header_item--icons"gt;amp;nbsp;lt;/divgt;  lt;/divgt;  lt;div class="gfield_list_groups"gt;  lt;div class="gfield_list_row_odd gfield_list_group"gt;  lt;div class="gfield_list_group_item gfield_list_cell gfield_list_7_cell1" data-label="First Name"gt;lt;input aria-invalid="false" aria-describedby="gfield_description_1_7" aria-label="First Name, Row 1" data-aria-label-template="First Name, Row {0}" type="text" name="input_7[]" value="asda"gt;lt;/divgt;  lt;div class="gfield_list_group_item gfield_list_cell gfield_list_7_cell2" data-label="Middle Name"gt;lt;input aria-invalid="false" aria-describedby="gfield_description_1_7" aria-label="Middle Name, Row 1" data-aria-label-template="Middle Name, Row {0}" type="text" name="input_7[]" value="asdadad"gt;lt;/divgt;  lt;div class="gfield_list_group_item gfield_list_cell gfield_list_7_cell3" data-label="Last Name"gt;lt;input aria-invalid="false" aria-describedby="gfield_description_1_7" aria-label="Last Name, Row 1" data-aria-label-template="Last Name, Row {0}" type="text" name="input_7[]" value="a"gt;lt;/divgt;  lt;div class="gfield_list_group_item gfield_list_cell gfield_list_7_cell4" data-label="Date of Birth (MM/DD/YY)"gt;lt;input aria-invalid="false" aria-describedby="gfield_description_1_7" aria-label="Date of Birth (MM/DD/YY), Row 1" data-aria-label-template="Date of Birth (MM/DD/YY), Row {0}" type="text" name="input_7[]" value="d"gt;lt;/divgt;  lt;div class="gfield_list_group_item gfield_list_cell gfield_list_7_cell5" data-label="Relationship"gt;  lt;select name="input_7[]" aria-invalid="false" aria-describedby="gfield_description_1_7" aria-label="Relationship, Row 1" data-aria-label-template="Relationship, Row {0}"gt;  lt;option value="My Child" selected="selected"gt;My Childlt;/optiongt;  lt;option value="Our Child"gt;Our Childlt;/optiongt;  lt;option value="Spouse's Child"gt;Spouse's Childlt;/optiongt;  lt;/selectgt;  lt;/divgt;  lt;div class="gfield_list_group_item gfield_list_cell gfield_list_7_cell6" data-label="Special Needs"gt;  lt;select name="input_7[]" aria-invalid="false" aria-describedby="gfield_description_1_7" aria-label="Special Needs, Row 1" data-aria-label-template="Special Needs, Row {0}"gt;  lt;option value="Please Select"gt;Please Selectlt;/optiongt;  lt;option value="No" selected="selected"gt;Nolt;/optiongt;  lt;option value="Yes"gt;Yeslt;/optiongt;  lt;/selectgt;  lt;/divgt;  lt;div class="gfield_list_icons"gt; lt;button type="button" class="add_list_item " aria-label="Add another row" onclick="gformAddListItem(this, 0)"gt;Addlt;/buttongt; lt;button type="button" class="delete_list_item" aria-label="Remove row 1" data-aria-label-template="Remove row {0}" onclick="gformDeleteListItem(this, 0)" style="visibility:hidden;"gt;Removelt;/buttongt;lt;/divgt;  lt;/divgt;  lt;/divgt;  lt;/divgt;  lt;/divgt;  lt;/fieldsetgt;  lt;fieldset id="field_1_66" class="gfield switch-field gfield_contains_required field_sublabel_below field_description_above gfield_visibility_visible" style="display: none;"gt;  lt;legend class="gfield_label"gt;Are you married?lt;span class="gfield_required"gt;lt;span class="gfield_required gfield_required_text"gt;(Required)lt;/spangt;lt;/spangt;lt;/legendgt;  lt;div class="ginput_container ginput_container_radio"gt;  lt;div class="gfield_radio" id="input_1_66"gt;  lt;div class="gchoice gchoice_1_66_0"gt;  lt;input class="gfield-choice-input" name="input_66" type="radio" value="Yes" checked="checked" id="choice_1_66_0" onchange="gformToggleRadioOther( this )"gt;  lt;label for="choice_1_66_0" id="label_1_66_0"gt;Yeslt;/labelgt;  lt;/divgt;  lt;div class="gchoice gchoice_1_66_1"gt;  lt;input class="gfield-choice-input" name="input_66" type="radio" value="No" id="choice_1_66_1" onchange="gformToggleRadioOther( this )"gt;  lt;label for="choice_1_66_1" id="label_1_66_1"gt;Nolt;/labelgt;  lt;/divgt;  lt;/divgt;  lt;/divgt;  lt;/fieldsetgt;  lt;/divgt;  lt;/divgt;  lt;div class="gform_page_footer top_label"gt;  lt;input type="button" id="gform_previous_button_1_297" class="gform_previous_button button" value="Previous" onclick="jQuery(amp;quot;#gform_target_page_number_1amp;quot;).val(amp;quot;1amp;quot;); jQuery(amp;quot;#gform_1amp;quot;).trigger(amp;quot;submitamp;quot;,[true]); " onkeypress="if( event.keyCode == 13 ){ jQuery(amp;quot;#gform_target_page_number_1amp;quot;).val(amp;quot;1amp;quot;); jQuery(amp;quot;#gform_1amp;quot;).trigger(amp;quot;submitamp;quot;,[true]); } "gt; lt;input type="button" id="gform_next_button_1_297" class="gform_next_button button" value="Next" onclick="jQuery(amp;quot;#gform_target_page_number_1amp;quot;).val(amp;quot;3amp;quot;); jQuery(amp;quot;#gform_1amp;quot;).trigger(amp;quot;submitamp;quot;,[true]); " onkeypress="if( event.keyCode == 13 ){ jQuery(amp;quot;#gform_target_page_number_1amp;quot;).val(amp;quot;3amp;quot;); jQuery(amp;quot;#gform_1amp;quot;).trigger(amp;quot;submitamp;quot;,[true]); } "gt;   lt;button type="button" id="gform_save_1_3_link" class="gform_save_link button" onclick="if(window[amp;quot;gf_submitting_1amp;quot;]){return false;} if( !jQuery(amp;quot;#gform_1amp;quot;)[0].checkValidity || jQuery(amp;quot;#gform_1amp;quot;)[0].checkValidity()){window[amp;quot;gf_submitting_1amp;quot;]=true;} jQuery(amp;quot;#gform_save_1amp;quot;).val(1); jQuery(amp;quot;#gform_1amp;quot;).trigger(amp;quot;submitamp;quot;,[true]);" onkeypress="if( event.keyCode == 13 ){ if(window[amp;quot;gf_submitting_1amp;quot;]){return false;} if( !jQuery(amp;quot;#gform_1amp;quot;)[0].checkValidity || jQuery(amp;quot;#gform_1amp;quot;)[0].checkValidity()){window[amp;quot;gf_submitting_1amp;quot;]=true;} jQuery(amp;quot;#gform_save_1amp;quot;).val(1); jQuery(amp;quot;#gform_1amp;quot;).trigger(amp;quot;submitamp;quot;,[true]); }"gt;  lt;svg aria-hidden="true" focusable="false" width="16" height="16" fill="none" xmlns="http://www.w3.org/2000/svg"gt;  lt;path fill-rule="evenodd" clip-rule="evenodd" d="M0 8a4 4 0 004 4h3v3a1 1 0 102 0v-3h3a4 4 0 100-8 4 4 0 10-8 0 4 4 0 00-4 4zm9 4H7V7.414L5.707 8.707a1 1 0 01-1.414-1.414l3-3a1 1 0 011.414 0l3 3a1 1 0 01-1.414 1.414L9 7.414V12z" fill="#6B7280"gt;lt;/pathgt;  lt;/svggt;  Save and Continue Later  lt;/buttongt;  lt;/divgt; lt;/divgt;  

я попробовал следующие решения

 jQuery(this).find("input[type=button]:focus").val() //works on firefox/chrome not on safari $(document.activeElement).val() //works on firefox/chrome not on safari  

имея в виду, что мои возможности ограничены, поскольку у меня нет доступа к реальной форме, я не могу добавлять какие-либо атрибуты. кто-нибудь знает, как с этим справиться?

Комментарии:

1. можете ли вы поделиться своей HTML-частью?

2. исходный вопрос обновлен