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