简体   繁体   English

DirtyForms 不适用于输入隐藏字段

[英]DirtyForms does not work on input hidden field

I added dirtyForms to my forms to detect any changes on one of the input fields https://github.com/snikch/jquery.dirtyforms我在 forms 中添加了dirtyForms,以检测输入字段之一 https://github.com/snikch/jquery.dirtyforms的任何更改

HTML HTML

<form>
  <input type="text" id="post" name="post">
    
  <input type="hidden" id="body" name="body">
  <froala-editor input="body">

  </froala-editor>
</form>

Javascript Javascript

$('document').ready(function() {
   $('form').dirtyForms();
});

However for input hidden seems like it doesn't add the dirty class, it only works for input type="text" .但是对于隐藏的输入似乎它不会添加脏 class,它仅适用于input type="text" Any ideas on how to solve this problem?关于如何解决这个问题的任何想法?

Because it does not make sense when the user is not the one entering the data in the field.因为当用户不是在字段中输入数据的人时,它没有意义。

You can do it yourself你可以自己做

SO does not allow the editor so I tested here SO不允许编辑所以我在这里测试

$('form').toggleClass('mydirty', e.target.textContent !== "");

tests the editor, it makes more sense than the input field测试编辑器,它比输入字段更有意义

https://plungjan.name/SO/froala/ https://plungjan.name/SO/froala/

$('form').dirtyForms({
  helpers: [{
    isDirty: function($node, index) {
      if ($node.is('form')) {
        return $node.hasClass('mydirty');
      }
    }
  }]
});

var editor = new FroalaEditor('#froala')

$(document).on("keyup", function(e) {
  $('form').toggleClass('mydirty', e.target.textContent !== "");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.dirtyforms/2.0.0/jquery.dirtyforms.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/froala-editor@3.2.3/js/froala_editor.min.js"></script>
<form>
  <input type="text" id="post" name="post">

  <input type="hidden" id="body" name="body">
  <div id="froala" input="body">

  </div>
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM