Skip to content

Commit

Permalink
feat: work on readOnly calculated values
Browse files Browse the repository at this point in the history
  • Loading branch information
albanm committed Oct 17, 2023
1 parent 5c1f57b commit ca28b96
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
28 changes: 28 additions & 0 deletions doc/examples/dev/_calculated-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const id = '_calculated-value'

const title = 'Calculate the value of a property'

const description = ``

const schema = {
type: 'object',
properties: {
string1: {
title: `I'm a string whose value is used to calculate the next property`,
type: 'string'
},
string2: {
title: `I'm a string whose value is calculated`,
type: 'string',
readOnly: true,
'x-options': { evalMethod: 'evalExpr' },
'x-constExpr': '"Hello " || parent.value.string1 || " !"'
}
}
}

const model = {
string1: 'world'
}

export default { id, title, description, schema, model }
4 changes: 3 additions & 1 deletion doc/examples/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ArrayRichExpression from './_array_rich_expression'
import ArrayOneOfTitle from './_array_oneof_title'
import ReadonlyOptions from './_readonly-options'
import StringDefault from './_string_default'
import CalculatedValue from './_calculated-value'

const examplesGroup = {
title: 'Development',
Expand All @@ -42,7 +43,8 @@ const examplesGroup = {
ArrayRichExpression,
ArrayOneOfTitle,
ReadonlyOptions,
StringDefault
StringDefault,
CalculatedValue
]
}

Expand Down
10 changes: 9 additions & 1 deletion lib/VJsfNoDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,15 @@ export default {
if (this.fullSchema.type === 'array') {
value = this.value.filter(item => ![undefined, null].includes(item))
}
return this.input(this.fixProperties(value), true)

// Case of a select based on an array somewhere in the data
if (this.fullSchema['x-constExpr']) {
this.$watch(() => this.getFromExpr(this.fullSchema['x-constExpr']), (val) => {
this.input(val, true)
}, { immediate: true })
} else {
return this.input(this.fixProperties(value), true)
}
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"test-update": "jest --updateSnapshot",
"doc-build": "(cd doc && TARGET=https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/ nuxt generate)",
"doc-master": "(cd doc && TARGET=https://koumoul-dev.github.io/vuetify-jsonschema-form/master/ nuxt generate) && gh-pages-multi deploy -v -s doc/dist -t master",
"doc-2x": "(cd doc && TARGET=https://koumoul-dev.github.io/vuetify-jsonschema-form/2.x/ nuxt generate) && gh-pages-multi deploy -v -s doc/dist -t 2.x",
"analyze": "webpack --profile --json > dist/stats.json && webpack-bundle-analyzer dist/stats.json"
},
"jest": {
Expand Down

0 comments on commit ca28b96

Please sign in to comment.