如何禁用MVC HTML字段?

问题描述 投票:0回答:1

我有一个create.html表单,其中包含从我的spring roo 2.0域模型生成的字段:

<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>

我想在用户界面中禁用该字段。我试图将disabled属性添加到input字段定义中:

<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>

这暂时有效,但是spring roo在重新生成表单时会删除此disabled属性。

如何永久设置此属性?

spring-roo
1个回答
0
投票

看来我只需要设置属性:

data-z="user-managed" 

在该字段的form-group中。

© www.soinside.com 2019 - 2024. All rights reserved.