使用选择删除必需属性

Remove required attribute using selectize

本文关键字:属性 删除 选择      更新时间:2023-09-26

我正在使用选择来选择多个国家。我有一个复选框来选择所有国家/地区。

现在,如果以这种方式选中复选框,则禁用了选择字段。

$("#outbound_countries").selectize({
            delimeter: ',',
            plugins: ['remove_button'],
            persist: false,
            create: function(input) {
                return {
                    value: input,
                    text: input
                }
            }
        });

这是我的网页

<div class="form-group">
        <label for="outbound_countries" class="col-sm-3 control-label"> Outbound SMS Countries: </label>
        <div class="col-sm-4">
            <select id="outbound_countries" name="outbound_sms_countries" class="form-control" multiple required enabled />
            {% for country in country_list %}
                <option value="{{country.iso}}">
                    {{ country.printable_name }}
                </option>
            {% endfor %}
            </select>
            <input type="checkbox" name="outbound_all_countries" id="outbound_all_countries" required /> All Countries
        </div>
    </div>

因此,对于复选框和选择字段,我都有必需的属性。如果我选中该复选框,如何使用 selectize 删除所需的属性?

另外,如果我在选择框中选择国家/地区,如何使用选择从该选择框中获取所选值?

您可以使用此代码,该代码是 selectz 用于选择 selectz 多个

var Selectz = require('selectize');

Selectz.define('no-delete', function(option) {
  this.deleteSelection = function() {};
});

$("select[name='State-code']").selectz({
    plugins:{
        'no-delete': {}
    },
});