Skip to content

novalidate custom fields in page create dialog #7101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions panel/src/components/Forms/Field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@
</template>

<script>
import { disabled, help, id, label, name, required } from "@/mixins/props.js";
import {
disabled,
help,
id,
label,
name,
novalidate,
required
} from "@/mixins/props.js";

export const props = {
mixins: [disabled, help, id, label, name, required],
mixins: [disabled, help, id, label, name, novalidate, required],
props: {
buttons: Array,
counter: [Boolean, Object],
Expand Down
2 changes: 1 addition & 1 deletion panel/src/components/Forms/Field/BlocksField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</template>

<k-input-validator
v-bind="{ min, max, required }"
v-bind="{ min, max, novalidate, required }"
:value="JSON.stringify(value)"
>
<k-blocks
Expand Down
3 changes: 3 additions & 0 deletions panel/src/components/Forms/Field/DateField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
:value="iso.date"
:min="min"
:max="max"
:novalidate="novalidate"
@input="onDateInput"
/>
</k-dropdown-content>
Expand All @@ -39,6 +40,7 @@
ref="timeInput"
:disabled="disabled"
:display="time.display"
:novalidate="novalidate"
:required="required"
:step="time.step"
:value="iso.time"
Expand All @@ -58,6 +60,7 @@
<k-dropdown-content ref="times" align-x="end">
<k-timeoptions-input
:display="time.display"
:novalidate="novalidate"
:value="value"
@input="onTimesInput"
/>
Expand Down
2 changes: 1 addition & 1 deletion panel/src/components/Forms/Field/EntriesField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</template>

<k-input-validator
v-bind="{ min, max, required }"
v-bind="{ min, max, novalidate, required }"
:value="JSON.stringify(entries)"
>
<!-- Empty State -->
Expand Down
2 changes: 1 addition & 1 deletion panel/src/components/Forms/Field/LayoutField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</template>

<k-input-validator
v-bind="{ min, max, required }"
v-bind="{ min, max, novalidate, required }"
:value="JSON.stringify(value)"
>
<k-layouts
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Field/LinkField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
:id="id"
ref="input"
:disabled="disabled"
:novalidate="novalidate"
:pattern="currentType.pattern ?? null"
:placeholder="currentType.placeholder"
:required="required"
Expand Down
2 changes: 1 addition & 1 deletion panel/src/components/Forms/Field/ModelsField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<k-dropzone :disabled="!hasDropzone" @drop="drop">
<k-input-validator
v-bind="{ min, max, required }"
v-bind="{ min, max, novalidate, required }"
:value="JSON.stringify(value)"
>
<k-collection
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Field/ObjectField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<input
type="checkbox"
:checked="!isEmpty"
:formnovalidate="novalidate"
:required="required"
class="input-hidden"
/>
Expand Down
2 changes: 1 addition & 1 deletion panel/src/components/Forms/Field/StructureField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</template>

<k-input-validator
v-bind="{ min, max, required }"
v-bind="{ min, max, novalidate, required }"
:value="JSON.stringify(items)"
>
<template v-if="hasFields">
Expand Down
4 changes: 2 additions & 2 deletions panel/src/components/Forms/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
</template>

<script>
import { after, before, disabled } from "@/mixins/props.js";
import { after, before, disabled, novalidate } from "@/mixins/props.js";

export const props = {
mixins: [after, before, disabled],
mixins: [after, before, disabled, novalidate],
inheritAttrs: false,
props: {
autofocus: Boolean,
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/CalendarInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<input
:id="id"
:disabled="disabled"
:formnovalidate="novalidate"
:min="min"
:max="max"
:name="name"
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/CheckboxesInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default {
info: option.info,
label: option.text,
name: this.name ?? this.id,
novalidate: this.novalidate,
type: "checkbox",
value: option.value
};
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/ChoiceInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
value
}"
:class="[variant === 'invisible' ? 'sr-only' : null, $attrs.class]"
:formnovalidate="novalidate"
:data-variant="variant"
@input="$emit('input', $event.target.checked)"
/>
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/ColoroptionsInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
:autofocus="autofocus && index === 0"
:checked="choice.value === value"
:disabled="disabled"
:formnovalidate="novalidate"
:name="name ?? id"
:required="required"
:value="choice.value"
Expand Down
4 changes: 3 additions & 1 deletion panel/src/components/Forms/Input/ColorpickerInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
@input="$emit('input', $event)"
/>
<input
:formnovalidate="novalidate"
:name="name"
:required="required"
:value="formatted"
Expand Down Expand Up @@ -202,7 +203,8 @@ export default {
.k-colorpicker-input .k-coords-input {
border-radius: var(--rounded-sm);
aspect-ratio: 1/1;
background: linear-gradient(to bottom, transparent, #000),
background:
linear-gradient(to bottom, transparent, #000),
linear-gradient(to right, #fff, hsl(var(--h), 100%, 50%));
}
.k-colorpicker-input .k-alpha-input {
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/CoordsInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@keydown.delete="onDelete"
/>
<input
:formnovalidate="novalidate"
:name="name"
:required="required"
:value="value ? [value.x, value.y] : null"
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/DateInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:autofocus="autofocus"
:class="['k-string-input', `k-${type}-input`, $attrs.class]"
:disabled="disabled"
:formnovalidate="novalidate"
:placeholder="display"
:required="required"
:style="$attrs.style"
Expand Down
2 changes: 1 addition & 1 deletion panel/src/components/Forms/Input/MultiselectInput.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div :class="['k-multiselect-input', $attrs.class]" :style="$attrs.style">
<k-input-validator
v-bind="{ min, max, required }"
v-bind="{ min, max, novalidate, required }"
:value="JSON.stringify(value)"
anchor=".k-multiselect-input-toggle"
>
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/NumberInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
value: number
}"
:class="['k-number-input', $attrs.class]"
:formnovalidate="novalidate"
:style="$attrs.style"
type="number"
@blur="onBlur"
Expand Down
2 changes: 1 addition & 1 deletion panel/src/components/Forms/Input/PicklistInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<template v-if="filteredOptions.length">
<div class="k-picklist-input-body">
<k-input-validator
v-bind="{ min, max, required }"
v-bind="{ min, max, novalidate, required }"
:value="JSON.stringify(value)"
>
<component
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/RadioInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default {
info: option.info,
label: option.text,
name: this.name ?? this.id,
novalidate: this.novalidate,
type: "radio",
value: option.value
};
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/RangeInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
required,
step
}"
:formnovalidate="novalidate"
:value="position"
type="range"
@input="$emit('input', $event.target.valueAsNumber)"
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/SelectInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
:autofocus="autofocus"
:aria-label="ariaLabel"
:disabled="disabled"
:formnovalidate="novalidate"
:name="name"
:required="required"
:value="value"
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/StringInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
}"
:aria-label="ariaLabel"
:class="['k-string-input', $attrs.class]"
:formnovalidate="novalidate"
:data-font="font"
:style="$attrs.style"
@input="$emit('input', $event.target.value)"
Expand Down
2 changes: 1 addition & 1 deletion panel/src/components/Forms/Input/TagsInput.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div :data-can-add="canAdd" class="k-tags-input">
<k-input-validator
v-bind="{ min, max, required }"
v-bind="{ min, max, novalidate, required }"
:value="JSON.stringify(value)"
>
<k-tags
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/TextareaInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
value
}"
v-direction
:formnovalidate="novalidate"
:data-font="font"
class="k-textarea-input-native"
@click="$refs.toolbar?.close()"
Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/TimeoptionsInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<input
:id="id"
:disabled="disabled"
:formnovalidate="novalidate"
:min="min"
:max="max"
:name="name"
Expand Down
5 changes: 4 additions & 1 deletion panel/src/components/Forms/Input/TogglesInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
>
<legend class="sr-only">{{ $t("options") }}</legend>

<k-input-validator :required="required" :value="JSON.stringify(value)">
<k-input-validator
v-bind="{ novalidate, required }"
:value="JSON.stringify(value)"
>
<ul
:data-labels="labels"
:style="{ '--options': columns ?? options.length }"
Expand Down
3 changes: 2 additions & 1 deletion panel/src/components/Forms/Input/Validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class InputValidator extends HTMLElement {
static formAssociated = true;

static get observedAttributes() {
return ["min", "max", "required", "value"];
return ["min", "max", "novalidate", "required", "value"];
}

attributeChangedCallback(attribute, oldValue, newValue) {
Expand All @@ -20,6 +20,7 @@ export default class InputValidator extends HTMLElement {

this.max = null;
this.min = null;
this.novalidate = false;
this.required = false;
}

Expand Down
1 change: 1 addition & 0 deletions panel/src/components/Forms/Input/WriterInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<textarea
ref="output"
:formnovalidate="novalidate"
:name="name"
:required="required"
:value="value"
Expand Down
2 changes: 2 additions & 0 deletions panel/src/mixins/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import layout from "./props/layout.js";
import maxlength from "./props/maxlength.js";
import minlength from "./props/minlength.js";
import name from "./props/name.js";
import novalidate from "./props/novalidate.js";
import options from "./props/options.js";
import pattern from "./props/pattern.js";
import placeholder from "./props/placeholder.js";
Expand All @@ -34,6 +35,7 @@ export {
maxlength,
minlength,
name,
novalidate,
options,
pattern,
placeholder,
Expand Down
8 changes: 8 additions & 0 deletions panel/src/mixins/props/novalidate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
props: {
/**
* If `true`, the native browser validation will not be triggered
*/
novalidate: Boolean
}
};
6 changes: 6 additions & 0 deletions src/Form/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ public static function defaults(): array
'label' => function ($label = null) {
return I18n::translate($label, $label);
},
/**
* If `true`, the native browser validation will not be triggered for this field
*/
'novalidate' => function (bool $novalidate = false): bool {
return $novalidate;
},
/**
* Optional placeholder value that will be shown when the field is empty
*/
Expand Down
7 changes: 7 additions & 0 deletions src/Form/FieldClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ abstract class FieldClass

protected bool $disabled;
protected string|null $name;
protected bool $novalidate;
protected Fields $siblings;

public function __construct(
Expand All @@ -53,6 +54,7 @@ public function __construct(
$this->setLabel($params['label'] ?? null);
$this->setModel($params['model'] ?? null);
$this->setName($params['name'] ?? null);
$this->setNovalidate($params['novalidate'] ?? false);
$this->setPlaceholder($params['placeholder'] ?? null);
$this->setRequired($params['required'] ?? false);
$this->setSiblings($params['siblings'] ?? null);
Expand Down Expand Up @@ -171,6 +173,11 @@ protected function setName(string|null $name = null): void
$this->name = strtolower($name ?? $this->type());
}

protected function setNovalidate(bool $novalidate = false): void
{
$this->novalidate = $novalidate;
}

protected function setSiblings(Fields|null $siblings = null): void
{
$this->siblings = $siblings ?? new Fields([$this]);
Expand Down
3 changes: 3 additions & 0 deletions src/Panel/PageCreateDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ public function customFields(): array
// switch all fields to 1/1
$field['width'] = '1/1';

// switch off validation
$field['novalidate'] = ($this->blueprint()->create()['status'] ?? 'draft') !== 'draft';

// add the field to the form
$custom[$name] = $field;
}
Expand Down
Loading