vue-form-json-schema icon indicating copy to clipboard operation
vue-form-json-schema copied to clipboard

Default Value Not working

Open paolog22 opened this issue 4 years ago • 8 comments

{ "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

paolog22 avatar Jul 22 '20 13:07 paolog22

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 avatar Jul 24 '20 11:07 jarvelov

@jarvelov do you have example for radio input field- ( not using any vue bootstrap framework)?

rmuraliananth avatar Oct 16 '20 21:10 rmuraliananth

@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.

jarvelov avatar Oct 17 '20 08:10 jarvelov

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

rmuraliananth avatar Oct 19 '20 15:10 rmuraliananth

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 avatar Oct 19 '20 22:10 rmuraliananth

@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.

jarvelov avatar Oct 20 '20 10:10 jarvelov

@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

jarvelov avatar Oct 20 '20 20:10 jarvelov

@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

rmuraliananth avatar Oct 21 '20 15:10 rmuraliananth