submit section snippet
This commit is contained in:
@@ -2,6 +2,7 @@ import { UUITextStyles } from '@umbraco-ui/uui-css';
|
||||
import { css, html } from 'lit';
|
||||
import { customElement, property, query } from 'lit/decorators.js';
|
||||
import { UUIBooleanInputElement, UUIInputElement } from '@umbraco-ui/uui';
|
||||
import { getAddSectionSnippet, getRenderBodySnippet, getRenderSectionSnippet } from '../../utils';
|
||||
|
||||
@customElement('umb-insert-section-checkbox')
|
||||
export class UmbInsertSectionCheckboxElement extends UUIBooleanInputElement {
|
||||
@@ -16,15 +17,18 @@ export class UmbInsertSectionCheckboxElement extends UUIBooleanInputElement {
|
||||
showInput = false;
|
||||
|
||||
@query('uui-input')
|
||||
input!: UUIInputElement;
|
||||
input?: UUIInputElement;
|
||||
|
||||
@query('form')
|
||||
form!: HTMLFormElement;
|
||||
form?: HTMLFormElement;
|
||||
|
||||
@query('uui-checkbox')
|
||||
checkbox!: HTMLFormElement;
|
||||
checkbox?: HTMLFormElement;
|
||||
|
||||
validate() {
|
||||
|
||||
if(!this.form) return true;
|
||||
|
||||
this.form.requestSubmit();
|
||||
return this.form.checkValidity();
|
||||
}
|
||||
@@ -34,13 +38,14 @@ export class UmbInsertSectionCheckboxElement extends UUIBooleanInputElement {
|
||||
}
|
||||
|
||||
get inputValue() {
|
||||
return this.input.value;
|
||||
return this.input?.value;
|
||||
}
|
||||
|
||||
get isMandatory() {
|
||||
return this.checkbox.checked;
|
||||
return this.checkbox?.checked;
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
return html`
|
||||
${super.render()}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { UmbModalToken } from '@umbraco-cms/backoffice/modal';
|
||||
|
||||
import './insert-section-input.element';
|
||||
import UmbInsertSectionCheckboxElement from './insert-section-input.element';
|
||||
import { getAddSectionSnippet, getRenderBodySnippet, getRenderSectionSnippet } from '../../utils';
|
||||
|
||||
export const UMB_MODAL_TEMPLATING_INSERT_SECTION_MODAL = new UmbModalToken(
|
||||
UMB_MODAL_TEMPLATING_INSERT_SECTION_SIDEBAR_ALIAS,
|
||||
@@ -31,6 +32,9 @@ export default class UmbTemplatingInsertSectionModalElement extends UmbModalBase
|
||||
@state()
|
||||
selectedCheckbox?: UmbInsertSectionCheckboxElement | null = null;
|
||||
|
||||
@state()
|
||||
snippet = '';
|
||||
|
||||
#chooseSection(event: Event) {
|
||||
event.stopPropagation();
|
||||
const target = event.target as UmbInsertSectionCheckboxElement;
|
||||
@@ -41,6 +45,7 @@ export default class UmbTemplatingInsertSectionModalElement extends UmbModalBase
|
||||
}
|
||||
if (target.checked) {
|
||||
this.selectedCheckbox = target;
|
||||
this.snippet = this.snippetMethods[checkboxes.indexOf(target)](target?.inputValue as string, target?.isMandatory);
|
||||
checkboxes.forEach((checkbox) => {
|
||||
if (checkbox !== target) {
|
||||
checkbox.checked = false;
|
||||
@@ -53,13 +58,14 @@ export default class UmbTemplatingInsertSectionModalElement extends UmbModalBase
|
||||
this.selectedCheckbox = this.checkboxes[0];
|
||||
}
|
||||
|
||||
snippetMethods = [getRenderBodySnippet, getRenderSectionSnippet, getAddSectionSnippet];
|
||||
|
||||
#close() {
|
||||
this.modalHandler?.reject();
|
||||
}
|
||||
|
||||
#submit() {
|
||||
if(this.selectedCheckbox?.validate())
|
||||
this.modalHandler?.submit({ value: (this.selectedCheckbox?.inputValue as string) ?? '' });
|
||||
if (this.selectedCheckbox?.validate()) this.modalHandler?.submit({ value: this.snippet ?? '' });
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
Reference in New Issue
Block a user