mirror of
https://github.com/IT4Change/ohmyform-ui.git
synced 2025-12-13 09:45:50 +00:00
Fix some issues with Logic
values.hasOwnProperty(term) is needed as the if statement validates to false even if values contains the term but the value of the term is currently false (yes / no option with default no)
This commit is contained in:
parent
011a6baef4
commit
535c660f59
@ -9,7 +9,7 @@ export const useMath = (): ((
|
||||
) => boolean) => {
|
||||
return (expression, values) => {
|
||||
const parser = init(formula, (term: string) => {
|
||||
if (values[term]) {
|
||||
if (values.hasOwnProperty(term)) {
|
||||
return values[term]
|
||||
}
|
||||
|
||||
@ -17,20 +17,6 @@ export const useMath = (): ((
|
||||
})
|
||||
|
||||
try {
|
||||
let processed = expression
|
||||
|
||||
Object.keys(values).forEach((key) => {
|
||||
const r = new RegExp(key.replace('$', '\\$'), 'ig')
|
||||
|
||||
const test = r.test(processed)
|
||||
|
||||
if (test) {
|
||||
processed = processed.replace(r, String(values[key]))
|
||||
}
|
||||
})
|
||||
|
||||
parser.expressionToValue(expression)
|
||||
|
||||
return Boolean(parser.expressionToValue(expression))
|
||||
} catch (e) {
|
||||
logger(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user