0

Im not able to set an input to "checked" if e.g. a string is not null. I have no idea why, I googled a lot but nothing worked. This was the best I found but is seems to be wrong... at least it doesn't work for me.

enter image description here

This is the code I have for now:

<input type="checkbox" name="autowarn" value="checked" @if(autowarnVar != null){checked}>

IntelliJ tells me that the Tag is not closed, but it is, so where is the mistake?.. I haven't worked much with play until now, but I have other examples where it works, so I'm confused why it sometimes works an sometimes not?

theoretisch
  • 1,718
  • 5
  • 24
  • 34
  • Do you get a compile-time error when you actually compile the code above? I ask because I use `@if( condition ) { checked }` frequently, without compile issues. It looks like a possible intellij parsing problem. – wwkudu Oct 30 '17 at 07:52
  • I was not able to compile and run the code above. Got the same error then just in the browser and console. – theoretisch Oct 30 '17 at 14:25

1 Answers1

1

Try to set a checked value to checked attribute:

<input type="checkbox" name="autowarn" value="checked"
@if(autowarnVar != null){checked="checked"}>
Sergey Sklyar
  • 1,902
  • 1
  • 15
  • 27