首页 > 解决方案 > 除非选中,否则禁用日期输入,然后设为必填

问题描述

我正在处理以下表格,其中包含以下可供选择的选项值。如果选择了选项值“下面列出的以下时间段或访问日期的有限授权”,expdate则可以填写该字段。但是,我想让他们expdate填写必填字段。我怎样才能做到这一点?我非常感谢任何意见或建议,因为我在这方面没有受过任何教育,只是通过玩来学习............

HTML 代码的图像(如果需要)

<![CDATA[
                    <script type="text/javascript">
                        function $enableRequiredTextField($field) {
                            $field.val("");
                            $field.prop({"readonly": false,"tabIndex":0});
                            $field.removeAttr('style');
                        }

                        function $disableRequiredTextField($expdate) {
                            $field.val("N/A");
                            $field.prop({"readonly": true,"tabIndex":-1});
                            $field.css({"background-color": "#DDDDDD"});
                            $field.removeClass("alertborder");
                        }

                        $('#authorize').change(function() {//on change of select 
                          $('#expdate', ).prop('disabled', $('option:selected', this).val() != 'Limited authorization for the following time period or visit date(s) listed below');  
                          //check if value is not Limited authorization for the following time period or visit date(s) listed below then disable
                        }).change();//call on change manually so on load will run the change event
                        
        <inputField name="authorize" type="combo" prompt="Select an option from the drop down list:">
          <options>
            <option selected="true" />
            <option value="My authorization is not limited to a certain time period or visit date">My authorization is not limited to a certain time period or visit date</option>
            <option value="This authorization shall be in effect for 12 months following the date of signature">This authorization shall be in effect for 12 months following the date of signature</option>
            <option value="Limited authorization for the following time period or visit date(s) listed below">Limited authorization for the following time period or visit date(s) listed below</option>
          </options>
        </inputField>
        <inputField name="expdate" type="date" required="true" prompt="Date Authorized Until:" />
        <inputField name="mustCheck" type="checkbox">
          <options>
            <option value="true">I understand that this authorization will remain in effect until such time that I revoke it in writing.</option>
          </options>
        </inputField>
      </inputFields>
      <text type="submit" class="completeworkflow">Submit Request</text>

标签: javascriptrequire

解决方案


看看附图,我认为您指的是“mustCheck”对吗?尝试使用 name="mustCheck" 将 required 添加到 inputField。

<inputField name="mustCheck" type="checkbox" required>

html也有一个名为“disabled”的属性,所以

<inputField name="expdate" type="date" required="true" disabled="true" prompt="Date Authorized Until:" />

如果您想使用 JavaScript 启用该元素

document.getElementById('expdate').disabled = false;

如果你使用 jQuery

$('#expdate').prop('disabled', false);


推荐阅读