Fixing required checkbox

This commit is contained in:
Hugo LE DALL 2020-07-19 18:21:52 +02:00
parent bdd7c7e6bb
commit 86726706c3
2 changed files with 24 additions and 21 deletions

View File

@ -21,7 +21,7 @@
$: required = $: required =
field.constraints && field.constraints &&
field.constraints.presence && field.constraints.presence &&
!constraints.presence.allowEmpty !field.constraints.presence.allowEmpty
</script> </script>
<div class="info"> <div class="info">
@ -41,7 +41,10 @@
<div class="info"> <div class="info">
<div class="field"> <div class="field">
<label>Required</label> <label>Required</label>
<input type="checkbox" /> <input
type="checkbox"
bind:checked={required}
on:change={() => (field.constraints.presence.allowEmpty = required)} />
</div> </div>
{#if field.type === 'string'} {#if field.type === 'string'}

View File

@ -6,7 +6,7 @@ export const FIELDS = {
constraints: { constraints: {
type: "string", type: "string",
length: {}, length: {},
presence: false, presence: { allowEmpty: true },
}, },
}, },
NUMBER: { NUMBER: {
@ -15,7 +15,7 @@ export const FIELDS = {
type: "number", type: "number",
constraints: { constraints: {
type: "number", type: "number",
presence: false, presence: { allowEmpty: true },
numericality: {}, numericality: {},
}, },
}, },
@ -25,7 +25,7 @@ export const FIELDS = {
type: "boolean", type: "boolean",
constraints: { constraints: {
type: "boolean", type: "boolean",
presence: false, presence: { allowEmpty: true },
}, },
}, },
// OPTIONS: { // OPTIONS: {
@ -34,7 +34,7 @@ export const FIELDS = {
// type: "options", // type: "options",
// constraints: { // constraints: {
// type: "string", // type: "string",
// presence: false, // presence: { allowEmpty: true },
// }, // },
// }, // },
DATETIME: { DATETIME: {
@ -44,7 +44,7 @@ export const FIELDS = {
constraints: { constraints: {
type: "string", type: "string",
length: {}, length: {},
presence: false, presence: { allowEmpty: true },
}, },
}, },
// IMAGE: { // IMAGE: {
@ -53,7 +53,7 @@ export const FIELDS = {
// type: "file", // type: "file",
// constraints: { // constraints: {
// type: "string", // type: "string",
// presence: false, // presence: { allowEmpty: true },
// }, // },
// }, // },
// FILE: { // FILE: {
@ -62,7 +62,7 @@ export const FIELDS = {
// type: "file", // type: "file",
// constraints: { // constraints: {
// type: "string", // type: "string",
// presence: false, // presence: { allowEmpty: true },
// }, // },
// }, // },
LINKED_FIELDS: { LINKED_FIELDS: {
@ -84,7 +84,7 @@ export const BLOCKS = {
constraints: { constraints: {
type: "string", type: "string",
length: {}, length: {},
presence: false, presence: { allowEmpty: true },
}, },
}, },
COMPANY: { COMPANY: {
@ -94,7 +94,7 @@ export const BLOCKS = {
constraints: { constraints: {
type: "string", type: "string",
length: {}, length: {},
presence: false, presence: { allowEmpty: true },
}, },
}, },
EMAIL: { EMAIL: {
@ -104,7 +104,7 @@ export const BLOCKS = {
constraints: { constraints: {
type: "string", type: "string",
length: {}, length: {},
presence: false, presence: { allowEmpty: true },
}, },
}, },
PHONE_NUMBER: { PHONE_NUMBER: {
@ -113,7 +113,7 @@ export const BLOCKS = {
type: "number", type: "number",
constraints: { constraints: {
type: "number", type: "number",
presence: false, presence: { allowEmpty: true },
numericality: {}, numericality: {},
}, },
}, },
@ -123,7 +123,7 @@ export const BLOCKS = {
type: "number", type: "number",
constraints: { constraints: {
type: "number", type: "number",
presence: false, presence: { allowEmpty: true },
numericality: {}, numericality: {},
}, },
}, },
@ -133,7 +133,7 @@ export const BLOCKS = {
type: "boolean", type: "boolean",
constraints: { constraints: {
type: "boolean", type: "boolean",
presence: false, presence: { allowEmpty: true },
}, },
}, },
URL: { URL: {
@ -143,7 +143,7 @@ export const BLOCKS = {
constraints: { constraints: {
type: "string", type: "string",
length: {}, length: {},
presence: false, presence: { allowEmpty: true },
}, },
}, },
IMAGE: { IMAGE: {
@ -153,7 +153,7 @@ export const BLOCKS = {
constraints: { constraints: {
type: "string", type: "string",
length: {}, length: {},
presence: false, presence: { allowEmpty: true },
}, },
}, },
// PRIORITY: { // PRIORITY: {
@ -162,7 +162,7 @@ export const BLOCKS = {
// type: "options", // type: "options",
// constraints: { // constraints: {
// type: "string", // type: "string",
// presence: false, // presence: { allowEmpty: true },
// inclusion: ["low", "medium", "high"], // inclusion: ["low", "medium", "high"],
// }, // },
// }, // },
@ -173,7 +173,7 @@ export const BLOCKS = {
constraints: { constraints: {
type: "string", type: "string",
length: {}, length: {},
presence: false, presence: { allowEmpty: true },
}, },
}, },
// AVATAR: { // AVATAR: {
@ -182,7 +182,7 @@ export const BLOCKS = {
// type: "image", // type: "image",
// constraints: { // constraints: {
// type: "string", // type: "string",
// presence: false, // presence: { allowEmpty: true },
// }, // },
// }, // },
// PDF: { // PDF: {
@ -191,7 +191,7 @@ export const BLOCKS = {
// type: "file", // type: "file",
// constraints: { // constraints: {
// type: "string", // type: "string",
// presence: false, // presence: { allowEmpty: true },
// }, // },
// }, // },
} }