Merge pull request #467 from HugoLd/bugfix/model-required-checkbox

Fixing required checkbox #454 #461
This commit is contained in:
Michael Shanks 2020-07-20 09:52:02 +01:00 committed by GitHub
commit a3762d6c8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 },
// }, // },
// }, // },
} }