Search code examples
laravellaravel-validation

laravel-jsvalidation package not supporting for wysiwyg editor


I'm using a wysiwyg editor (bootstrap-wysihtml5) inside a laravel form instead of a text area. And I'm using laravel-jsvalidation to validate the form. But unfortunately front end validation is not happening for my wysiwyg editor field.

This is my text area code.

{!! JsValidator::formRequest('App\Http\Requests\MyFormRequest') !!}

<input type='text' name='title' />
<textarea name='content' class="textarea" placeholder="Enter text ..." 
style="width: 100%; height: 200px; font-size: 14px; line-height: 18px;"></textarea>

<script>
  $('.textarea').wysihtml5();
<script>

I use Form Requests to validate this and this is my request class.

class MyFormRequest extends FormRequest {

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules() {
        return [
            "title" => "required",
            "content" => "required",
        ];
    }

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize() {
        return true;
    }

}

Title field is perfectly validating but not the content field in js validation. It would be a great help if someone knows how to do it. (No errors are appearing too)


Solution

  • After long time of checking I found out the issue. it's the same issue like this link - How to validate wysiwyg editor using bootstrap validation

    This happens WYSIWYG Editor hides the textarea and jquery validation related laravel-jsvalidation not working with hidden fields. So we need to change the code like,

    CSS

    .textnothide {
        display: block !important;
        position: absolute;
        z-index: -1;
    }
    

    JS

    <script>
      $('.textarea').wysihtml5(
          events: {
            load: function () {
                $('.textarea').addClass('textnothide');
            }
        }
      );
    <script>
    

    Hope this question is not a duplicate since it's related to laravel-jsvalidation and keeping the answer in case anyone else has the same issue.