Disabling save button on binding drawer when handlebars statement is invalid.

This commit is contained in:
mike12345567 2021-01-26 14:09:31 +00:00
parent 182353d555
commit 19ed02be60
3 changed files with 20 additions and 12 deletions

View File

@ -13,8 +13,7 @@
export let bindableProperties export let bindableProperties
export let value = "" export let value = ""
export let bindingDrawer export let bindingDrawer
export let valid = true
let validity = true
$: value && checkValid() $: value && checkValid()
$: bindableProperties = getBindableProperties( $: bindableProperties = getBindableProperties(
@ -25,7 +24,7 @@
function checkValid() { function checkValid() {
// TODO: need to convert the value to the runtime binding // TODO: need to convert the value to the runtime binding
const runtimeBinding = readableToRuntimeBinding(bindableProperties, value) const runtimeBinding = readableToRuntimeBinding(bindableProperties, value)
validity = isValid(runtimeBinding) valid = isValid(runtimeBinding)
} }
function addToText(readableBinding) { function addToText(readableBinding) {
@ -75,7 +74,7 @@
bind:value bind:value
placeholder="Add text, or click the objects on the left to add them to the placeholder="Add text, or click the objects on the left to add them to the
textbox." /> textbox." />
{#if !validity} {#if !valid}
<p class="syntax-error"> <p class="syntax-error">
Current Handlebars syntax is invalid, please check the guide Current Handlebars syntax is invalid, please check the guide
<a href="https://handlebarsjs.com/guide/">here</a> <a href="https://handlebarsjs.com/guide/">here</a>

View File

@ -21,6 +21,7 @@
let bindingDrawer let bindingDrawer
let temporaryBindableValue = value let temporaryBindableValue = value
let anchor let anchor
let valid
$: bindableProperties = getBindableProperties( $: bindableProperties = getBindableProperties(
$currentAsset.props, $currentAsset.props,
@ -90,10 +91,11 @@
</Body> </Body>
</div> </div>
<heading slot="buttons"> <heading slot="buttons">
<Button thin blue on:click={handleClose}>Save</Button> <Button thin blue disabled={!valid} on:click={handleClose}>Save</Button>
</heading> </heading>
<div slot="body"> <div slot="body">
<BindingPanel <BindingPanel
bind:valid
value={safeValue} value={safeValue}
close={handleClose} close={handleClose}
on:update={e => (temporaryBindableValue = e.detail)} on:update={e => (temporaryBindableValue = e.detail)}

View File

@ -87,13 +87,6 @@ describe("test the array helpers", () => {
}) })
expect(output).toBe("a,b") expect(output).toBe("a,b")
}) })
it("should allow a complex case", async () => {
const output = await processString("{{ last ( sort ( unique array ) ) }}", {
array: ["a", "a", "d", "c", "e"]
})
expect(output).toBe("e")
})
}) })
describe("test the number helpers", () => { describe("test the number helpers", () => {
@ -274,4 +267,18 @@ describe("Test the literal helper", () => {
}) })
expect(output.b).toBe(1) expect(output.b).toBe(1)
}) })
})
describe("Cover a few complex use cases", () => {
it("should allow use of three different collection helpers", async () => {
const output = await processString(`{{ join ( after ( split "My name is: Joe Smith" " " ) 3 ) " " }}`, {})
expect(output).toBe("Joe Smith")
})
it("should allow a complex array case", async () => {
const output = await processString("{{ last ( sort ( unique array ) ) }}", {
array: ["a", "a", "d", "c", "e"]
})
expect(output).toBe("e")
})
}) })