简体   繁体   English

如何禁用 mvc html 字段?

[英]How to make a mvc html field disabled?

I have a create.html form that has fields generated from my spring roo 2.0 domain model:我有一个 create.html 表单,其中包含从我的 spring roo 2.0 域 model 生成的字段:

<div class="form-group has-error has-feedback" data-z="790e58b4" id="consultation-prediction-field" data-th-classappend="${#fields.hasErrors('prediction')}? 'has-error has-feedback'" data-th-class="form-group">
  <label for="prediction" class="col-md-3 control-label" data-th-text="#{label_consultation_prediction}">prediction</label>
  <div class="col-md-3">
    <input id="prediction" name="prediction" data-th-value="*{{prediction}}" type="text" class="form-control inputmask" placeholder="prediction" data-th-placeholder="#{label_consultation_prediction}" data-toggle="tooltip" aria-describedby="predictionStatus" data-inputmask-alias="numeric" data-inputmask-digits="2" />
      <span data-th-classappend="${#fields.hasErrors('prediction')}? 'glyphicon glyphicon-remove form-control-feedback'" class="glyphicon glyphicon-remove form-control-feedback" data-th-if="${#fields.hasErrors('prediction')}" aria-hidden="true"></span>
      <span id="prediction-error" class="help-block" data-th-if="${#fields.hasErrors('prediction')}" data-th-errors="*{prediction}">Error message.</span>
  </div>
</div>

I would like to disable the field in the UI.我想禁用 UI 中的字段。 I have tried to add a disabled attribute to the input field definition:我试图在input字段定义中添加一个disabled属性:

<div class="form-group has-error has-feedback" data-z="790e58b4" id="consultation-prediction-field" data-th-classappend="${#fields.hasErrors('prediction')}? 'has-error has-feedback'" data-th-class="form-group">
  <label for="prediction" class="col-md-3 control-label" data-th-text="#{label_consultation_prediction}">prediction</label>
  <div class="col-md-3">
    <input id="prediction" name="prediction" disabled data-th-value="*{{prediction}}" type="text" class="form-control inputmask" placeholder="prediction" data-th-placeholder="#{label_consultation_prediction}" data-toggle="tooltip" aria-describedby="predictionStatus" data-inputmask-alias="numeric" data-inputmask-digits="2" />
      <span data-th-classappend="${#fields.hasErrors('prediction')}? 'glyphicon glyphicon-remove form-control-feedback'" class="glyphicon glyphicon-remove form-control-feedback" data-th-if="${#fields.hasErrors('prediction')}" aria-hidden="true"></span>
      <span id="prediction-error" class="help-block" data-th-if="${#fields.hasErrors('prediction')}" data-th-errors="*{prediction}">Error message.</span>
  </div>
</div>

This works temporarily, but spring roo removes this disabled attribute when it regenerates the form.这暂时有效,但 spring roo 在重新生成表单时会删除此disabled属性。

How can I permanently set this attribute?如何永久设置此属性?

It appears that I just need to set the attribute:看来我只需要设置属性:

data-z="user-managed" 

In the form-group for the field.在该字段的form-group中。

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

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