简体   繁体   English

(对CSS框架进行材料化)'required'属性在实现选择标记中不起作用

[英](Materialize CSS Framework) 'required' attribute does not work in materialize select tag

This is the following HTML structure: 这是以下HTML结构:

<div class="input-field col s5 col m5">
   <select required id="passengerDestination" name="passengerDestination{{ $i }}" class="validate">
        <option selected="" disabled="" value="">Select Destination</option>
        <option selected="" disabled="" value="">Select value</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option>...</option>
    </select>
    <label class="white-text" for="passengerDestination">Destination</label>
 </div>

Please don't mind the {{ $i }} because I am using Laravel and the select tag is inside the @for loop. 请不要介意{{ $i }}因为我使用的是Laravel,并且select标记位于@for循环内。

The problem is that when I changed the class of the select tag to browser-default it triggers the required attribute of the select tag. 问题是,当我将选择标记的类更改为browser-default它将触发选择标记的必需属性。

But that is not the thing I want. 但这不是我想要的。 I want to use require attribute of the select tag without using the class browser-default . 我想使用select标签的require属性,而不使用类browser-default

How can this be done? 如何才能做到这一点?

Material Framework used: 使用的材料框架:

materializecss.com materializecss.com

The select you are seeing is a representation of the hidden, underlying native select. 您看到的选择是隐藏的基础本机选择的表示。 If you or some other code changes the native select, you need to call 如果您或其他代码更改了本机选择,则需要调用

$('{your selector}').material_select();

This will rebind the representation to the native select. 这会将表示形式重新绑定到本机选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM