Trix editor validation

一曲冷凌霜 提交于 2021-02-08 09:10:40

问题


Using Trix editor via Rails view helpers.

= form.rich_text_area :description, class: 'form-control', placeholder: 'Description'

Have some model 'required' validation for description.

The normal Rails behavior of wrapping fields with field_with_errors is not happening.

Has anyone managed to get Trix and the normal Rails validation behavior to work together?


回答1:


Ended up fixing this way..

- if job.errors[:description].count > 0
    .form-with-errors
       = form.rich_text_area :description, class: 'form-control', placeholder: 'Description'
            .invalid-feedback.d-block
              - job.errors[:description].each do |error|
                = error

and..

.form-with-errors {
  trix-editor {
    border-color: #dc3545;
  }
}


来源:https://stackoverflow.com/questions/57455653/trix-editor-validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!