dongming8867 2017-09-28 15:19
浏览 33
已采纳

ZendFramework:将表单元素视图帮助器InputErrorClass更改为“has-error”

I use the FormRow View Helper in my forms which works fine except for the fact that, when the element has errors, it adds 'input-error' to the class.

Since I am using Bootstrap3, I would like to use the 'has-error' class for the input element.

Is there a easy way to set the default InputErrorClass to 'has-error' without creating my own plugins that would extend ForRow or FormInput?

The Zend\Form\View\Helper\FormRow class has a public function (setInputErrorClass) that sets the inputErrorClass property but I can't seem to be able to use it since FormRow is a plugin, unless I am missing something about ZF and PHP.

  • 写回答

1条回答 默认 最新

  • dongpinyao2203 2017-09-28 19:02
    关注

    I assume you are using in your view:

    $this->formRow($element);
    

    You can add before you use formRow:

    $this->formRow()->setInputErrorClass('has-error');
    

    or

    $this->formRow()->setInputErrorClass('has-error')->render($element);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?