1

I want to validate input type hidden

I add this :

product: { 
    ignore: "",
    rules: {
        description: {
            required: true
        },
        ...
    },
},

It works. I success validate input type hidden

But in my form, it need to validate summernote too

I get some reference to validate summernote and the ignore must changed like this :

ignore: ":hidden:not(#summernote),.note-editable.panel-body"

It works. But the validate input type hidden not works

So if I use : ignore: "", the summernote validate not works

If I use : ignore: ":hidden:not(#summernote),.note-editable.panel-body", the input type hidden not works

How do I merge it so that both (input type hidden and summernote) can work fine?

moses toh
  • 12,344
  • 71
  • 243
  • 443

1 Answers1

2

ignore in this plugin means to "not validate"

So ignore: "" means to "ignore nothing"; validate everything, including hidden fields.

I get some reference to validate summernote and the ignore must changed like this :

ignore: ":hidden:not(#summernote),.note-editable.panel-body"

This line is saying to "ignore" two things from validation...

  1. :hidden:not(#summernote)
  2. .note-editable.panel-body

the input type hidden not works

Of course. Because your first part, :hidden:not(#summernote), is telling it to ignore everything hidden except for #summernote.

So if you want to validate all hidden fields, then you cannot put :hidden inside of ignore!

Only list the things here that you do not want to validate:

ignore: ".note-editable.panel-body"
Sparky
  • 98,165
  • 25
  • 199
  • 285
  • It's still not perfect. I use summernote to crud(there exist form add & edit data). If I add data, it works. But if I edit data, the required does not works. On the console exist error : `uncaught typeerror: cannot read property 'settings' of undefined`. I try change this : `ignore: ":hidden:not(#summernote),.note-editable.panel-body"`, it works. But the problem is the input type hidden not validate – moses toh Nov 07 '17 at 03:07
  • @SuccessMan, I cannot see your DOM or HTML structure so therefore I have no idea what you’ll need to ignore and what you need to validate. However, based on what little was provided in the OP, I’ve fully answered your question. – Sparky Nov 07 '17 at 03:19
  • @SuccessMan, so do you want to validate hidden fields or not? If you want to validate them, then you cannot have `:hidden` in the `ignore` list. You've shown us no hidden fields, no HTML markup at all, so it would be literally impossible for me to know how to write your code for you. Otherwise, I think I have explained the `ignore` option thoroughly enough for you to be able to figure out the proper jQuery selectors for yourself. – Sparky Nov 07 '17 at 03:26
  • Yes, I want to validate hidden field. But if I use this : `ignore: ".note-editable.panel-body"`, on the edit data, there exist error : `uncaught typeerror: cannot read property 'settings' of undefined` – moses toh Nov 07 '17 at 03:29
  • @SuccessMan, that is a generic error that could be triggered by anything in this plugin. You have not shown nearly enough code to solve that. Activate the `debug` option of the plugin and read the console log. Also create a jsFiddle demo AND show enough code in the OP to reproduce the issue. – Sparky Nov 07 '17 at 03:36
  • Okay. I will try it. But whether it can if I add operator ternary (condition) in ignone list? So if form add data, then the ignore : `ignore: ".note-editable.panel-body"`. If form edit data, then the ignore : `ignore: ":hidden:not(#summernote),.note-editable.panel-body"` – moses toh Nov 07 '17 at 04:05
  • @SuccessMan, of course not! You can only add a comma separated list of jQuery style selectors to that parameter, not a function. – Sparky Nov 07 '17 at 04:11
  • Okay. Btw, can I ignore hidden inputs with a particular class? So only ignore some class on the input hidden – moses toh Nov 07 '17 at 04:40
  • @SuccessMan, it will ignore whatever you put inside `ignore`. I thought that part was clear. In other words, put the class in `ignore` and it does not care if it’s hidden. – Sparky Nov 07 '17 at 04:43
  • https://stackoverflow.com/questions/20287567/ignore-all-hidden-div-but-not-one-in-jquery-validation. Seems it can – moses toh Nov 07 '17 at 04:53
  • @SuccessMan, seriously, you’re totally misunderstanding how this works. The DEFAULT value of `ignore` is `:hidden` and ANYTHING you put inside `ignore` will OVERRIDE thIs default. So if you only use a class, then it will only match the class, whether hidden or not. Get it now? I’m done. Good luck. – Sparky Nov 07 '17 at 05:09
  • Okay. I just try it directly on my project and it works. Thanks for your help – moses toh Nov 07 '17 at 05:18