문제

I'm trying to make a nullable integer, that is an integer which can also have a value set as null.

To do this, I was hoping to have an integer input with a check box to signify it is null (which could then have JavaScript hook up to disable/enable the integer input).

I see three ways of doing this:

  1. Have a custom Type which has two fields.
  2. Have a custom form widget which handles the two.
  3. Some combination of one and two.

I'm not having any trouble with that, it's pretty straight forward.

What I can't seem to find any documentation about is how to get those two fields to funnel in to a single variable.

Any ideas?

도움이 되었습니까?

해결책

The best way I can see is applying a form transformer to your form.

If the checkbox is checked you set null to your property, if it isn't you assign the value of your integer widget.

You can have a look here and apply this to your particular case.

Side note: I wouldn't do this in the controller, it's not his job.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top