当JavaScript更改值时,检查单选按钮持久性

时间:2016-01-05 10:48:58

标签: javascript html forms

我有一个解决方法,所以我只是好奇而不是实际需要一个解决方案。

我有一个客户端验证表单,如果验证通过:

  1. 隐藏表单(用户输入值保持不变)
  2. 在同一页面中构建并显示无序列表 ,总结将要提交的内容
  3. 在摘要列表中,为用户提供在最终提交表单之前进行更改的选项。
  4. 其中一个字段是一个单选按钮组,其中每个选项的值都是JavaScript关闭时2个数据的组合:

     <LinearLayout
                android:id="@+id/ln"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:orientation="horizontal"
                android:visibility="visible"
                android:background="#5f6799"
                >
    
    
                <EditText
                    android:id="@+id/edComments"
                    android:layout_width="120dp"
                    android:layout_height="match_parent"
                    android:layout_marginTop="6dp"
                    android:layout_marginBottom="6dp"
                    android:layout_weight="0.95"
                    android:layout_marginLeft="11dp"
                    android:layout_marginRight="8dp"
                     android:scrollbars="vertical"
                    android:paddingLeft="5dp"
                    android:maxLength="140"
                    android:inputType="textMultiLine|textCapSentences"
                    android:imeOptions="actionDone"
                    android:ems="10"
                    android:hint="Write your comment here"
                    android:textColor="@color/my_dark_gray"
                    android:background="@color/white"
                    android:textSize="13sp"
                    />
    
            </LinearLayout>
    

    当存在JavaScript时,该值将被拆分:

    <input type="radio" name="date" value="{productCode}: {DD Mmm YYYY}">
    

    当用户将验证过渡到摘要页面状态时,会发生此拆分。

    A。如果他们继续直接提交表单,他们的日期选择仍然存在,一切正常。

    B。但是(至少在Chrome 47中)当用户进入摘要状态然后进行更改(到其他字段)时,他们的日期选择是<表单提交时强>丢失,因此服务器端验证报告错误。

    即使用户选择进行更改,也会发生这种情况:

    • 选择的日期不会被搞乱 - 表单只会再次显示,摘要<input type="hidden" name="product-code" value="{productCode}"> <input type="radio" name="date" value="{DD Mmm YYYY}"> 会清除文字并隐藏
    • 所选单选按钮仍显示为已选中

    这是当用户决定进行更改时调用的jQuery函数:

    ul

    当分割日期和代码值后,JavaScript在所选日期中添加显式function changeBooking() { // assume changes will be made so clear summary values $('#summary li[id^="summary-"] > [data-value]').text(''); // switch views from summary back to booking form $('#summary, #do-booking').hide(); $('#book fieldset.panel, #do-summary').show(); $('#book').scrollView(20); } 属性时,仍然会发生这种情况。

    所以我推断某种内部浏览器事件正在发生,我无法想象。

    如果有人能够提出为什么案例A和B之间的单选按钮选择持久性存在差异,我将不胜感激。

    对于它的价值,我的解决方法是将无线电组的初始值显示在checked中,这是一个永远不会搞砸的字段值。并且JavaScript将值拆分为2个隐藏字段 - name="code-date"name="product-code" - 这些字段最初为空白,并且在JavaScript关闭时保持不变。

0 个答案:

没有答案