Skip to content

Commit

Permalink
fix: fix form hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Aug 25, 2024
1 parent 3f0c1c3 commit eecd268
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
type MaybeConditionGroup,
toMaybeConditionGroup,
parseValidViewFilter,
formOption,
} from "@undb/table"
import { Switch } from "$lib/components/ui/switch"
import { Label } from "$lib/components/ui/label"
Expand All @@ -22,6 +21,7 @@
import type { ZodUndefined } from "@undb/zod"
import { writable } from "svelte/store"
import { Button } from "$lib/components/ui/button"
import { Checkbox } from "$lib/components/ui/checkbox"
const table = getTable()
Expand Down Expand Up @@ -57,6 +57,7 @@
}
$: previousFields = form.getPreviousFields(field.id.value) ?? []
$: disabled = formField.getRequired(field) && !formField.defaultValue
</script>

<div
Expand Down Expand Up @@ -108,20 +109,22 @@
<span>required</span>
</Label>

<label class={cn(formField.required ? "cursor-not-allowed" : "cursor-pointer")}>
<input
type="checkbox"
<Label class={cn(disabled ? "cursor-not-allowed" : "cursor-pointer")}>
<Checkbox
class="hidden"
bind:checked={formField.hidden}
disabled={formField.getRequired(field) && !formField.defaultValue}
on:click={setForm}
{disabled}
onCheckedChange={async () => {
await tick()
setForm()
}}
/>
{#if formField.hidden}
<EyeClosed class="h-4 w-4" />
{:else}
<EyeOpen class="h-4 w-4" />
{/if}
</label>
</Label>
</div>
</div>
<Collapsible.Content class="mt-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,14 @@
class="hidden"
bind:checked={formField.hidden}
disabled={hiddenDisabled}
on:change={setForm}
on:change={async () => {
if (hiddenDisabled) {
return
}

await tick()
setForm()
}}
/>
{#if formField.hidden}
<EyeClosed class="h-4 w-4" />
Expand Down
3 changes: 0 additions & 3 deletions packages/table/src/modules/forms/form/form-field.vo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export class FormFieldVO extends ValueObject<IFormField> {
}

public get hidden() {
if (this.required) {
return false
}
return this.props.hidden ?? false
}

Expand Down

0 comments on commit eecd268

Please sign in to comment.