vue-form-json-schema
vue-form-json-schema copied to clipboard
Default Value Not working
{ "schema": { "type": "object", "properties": { "ownersvehicle_id": { "type": "string" }, "vin": { "type": "string" }, "licence_number": { "type": "string", "default": "value test" }, "brand": { "type": "string" } }
license_number
has no default value on render
Hi,
The schema
property is only used for the JSON Schema, and while this assigns a default value for the JSON Schema's validation, it will not have any effect on the visual output. If you want to use a default value that is also visible in the UI then you want to set the default value in the model
:
model: {
licence_number: "value test"
},
See this example: https://codesandbox.io/s/example-1-8oi1c?file=/src/components/example-one.vue:1777-1778
@jarvelov do you have example for radio input field- ( not using any vue bootstrap framework)?
@rmuraliananth Yes of course. Just to clarify: all but one of the examples from the README uses native HTML elements, but with bootstrap class names, however they are not required in any way to use VFJS.
Here is an example of just a radio input without any bootstrap styling at all: https://codesandbox.io/s/example-1-forked-pvgl9 You can also see an example of a radio input field in the Registration Form Example.
Thanks @jarvelov for providing radio input example. but the problems is if the model { "answer": true }
has default value , It is not showing radio option is selected
Thanks @jarvelov for providing radio input example. but the problems is if the model
{ "answer": true }
has default value , It is not showing radio option is selected
Further Analysis, Setting default selected for radio option can be achieved through dynamicOptions
"dynamicOptions": { "model": "answer", "schema": { "const": true }, "options": { "fieldOptions": { "domProps": { "checked": "true" } } } }
https://codesandbox.io/s/example-1-forked-8yg2i?fontsize=14&hidenavigation=1&theme=dark
@rmuraliananth That was a clever solution with dynamicOptions
, however I feel that a workaround like that shouldn't be required. I'll work on a solution tonight and see if I can come up with a fix to have a radio button be checked by default just by having the model
value set.
@rmuraliananth I've worked out a solution which I think gets the job done. I've released the fix in v2.8.8-alpha.0
.
Here's a sandbox with the updated example from before: https://codesandbox.io/s/example-1-forked-xfmj3
@rmuraliananth I've worked out a solution which I think gets the job done. I've released the fix in
v2.8.8-alpha.0
.Here's a sandbox with the updated example from before: https://codesandbox.io/s/example-1-forked-xfmj3
Awesome :) Thanks! it works