在Laravel 5.7应用中,使用tinyMCE编辑器进行验证

时间:2018-11-03 08:28:51

标签: validation laravel-5 tinymce

在我的Laravel 5.7应用程序中,我使用laravel-jsvalidation插件(https://github.com/proengsoft/laravel-jsvalidation/wiki/Basic-Usage) 一切正常, 我需要将textarea输入包含为tinyMCE编辑器,并使用i进行验证,并使用2个textarea输入实现了它:

<div class="form-row mb-3 {{ in_array('description', $errorFieldsArray) ? 'validation_error' : '' }}">
    <label class="col-xs-12 col-sm-4 col-form-label">Description</label>
    <div class="col-xs-12 col-sm-8">
        <span style="display: inline;">
            {{ Form::textarea('description', isset($vote->description) ? $vote->description : '', [   "class"=>"form-control editable_field textarea_input ", "rows"=>"0", "cols"=> 120, "id"=>"description", "autocomplete"=>"off", "style"=>"width:0; height:0" ] ) }}
        </span>
        {{ Form::textarea('description_container', isset($vote->description) ? $vote->description : '', [   "class"=>"form-control editable_field textarea_input ", "rows"=>"5", "cols"=> 120,  "id"=>"description_container", "autocomplete"=>"off"  ] ) }}
    </div>
</div>

其中第一个文本区域用于表单提交,将输入的内容从第二个文本区域复制到该文本区域,用作 tinyMCE编辑器。 在tinyMCE定义中,我添加了以下行:

 setup: function (editor) {
     editor.on('change', function () {
         var current_context= tinymce.get(by_selector_container).getContent()
         $('#' + by_selector).html( current_context );
     });
 },

其中by_selector_container和by_selector是这些文本区域输入的名称。它可以工作,但是在页面上我只能看到第一个textarea输入的唯一问题, 尽管我尝试按照上面代码的样式将权重/高度设置为0来隐藏它,但是无论如何,我仍然看到小的textarea输入:https://imgur.com/a/43FRFJU

我尝试声明要设置的第一个textarea输入

"style"=>"display:none"

隐藏了超过textarea的输入,但是验证根本不起作用。

如何在验证有效的情况下隐藏此小文本区域输入?

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以尝试样式:

<script>
var x = document.getElementById("demo");
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude + 
    "<br>Longitude: " + position.coords.longitude; 
}
</script>