简体   繁体   中英

Grails number field won't allow blank answer

I am using Grails 3. I have the following field:

<g:field id="myVar" name="myVar" type="number" value="${this.myController?.myVar}"/>

Domain class:

class myDomain{
  int myVar
  static constraints ={
     myVar nullable:true, blank:true
  }
}

When I try to submit this field, it will not allow a blank answer. I have it set up in my constraints in the domain class that this field can be null and blank. All of the number fields inside of my form are giving me this error, yet I can leave other fields blank. This is the error message:

Property myVar is type-mismatched 

Is there a setting I am missing?

int is a primitive type. It will never be null. You should have Integer. Also you should remove "blank" constraint. It make sense only for String type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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