informative icon indicating copy to clipboard operation
informative copied to clipboard

Ability to set default false value for checkbox fields

Open iamvanja opened this issue 6 years ago • 1 comments

I need a way to turn empty string into '0' or at least 0 for checkboxes.

Currently I am mapping those values on submit, however it requires to keep track of which fields are checkboxes (working with big forms). To avoid keeping track of field types, I thought to look for checked property as a way to differentiate checkboxes from other fields, but the only thing available is formState.fields[name].props.checked which are initial props and do not update.

Ideally, this would be dealt with on a field instance and not submit. Also looked into creating a separate CheckboxField component, but it seems that '' is hardcoded in the Informative internals, so dealing with it there is too late. How about an uncheckedValue prop?

What would be the best way to do this?

Thanks

iamvanja avatar Jun 14 '18 18:06 iamvanja

Yea I'm gonna have to think about this and try a few things out. Your idea for a prop for the unchecked value might pan out

bradwestfall avatar Jun 22 '18 21:06 bradwestfall