Skip to content

Commit 1e7a4fa

Browse files
committed
more documentation
1 parent c7048d9 commit 1e7a4fa

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

packages/uui-base/lib/mixins/FormControlMixin.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,22 @@ export const FormControlMixin = <T extends Constructor<LitElement>>(
168168
});
169169
}
170170

171+
/**
172+
* Determn wether this FormControl has a value.
173+
* @method hasValue
174+
* @returns {boolean}
175+
*/
171176
public hasValue(): boolean {
172177
return this.value !== '';
173178
}
174179

180+
/**
181+
* Get internal form element.
182+
* This has to be implemented to provide a FormControl Element of choice for the given context. The element is used as anchor for validation-messages.
183+
* @abstract
184+
* @method getFormElement
185+
* @returns {HTMLElement | undefined}
186+
*/
175187
protected abstract getFormElement(): HTMLElement | undefined;
176188

177189
disconnectedCallback(): void {
@@ -184,6 +196,21 @@ export const FormControlMixin = <T extends Constructor<LitElement>>(
184196
}
185197
}
186198

199+
/**
200+
* Add validator, to validate this Form Control.
201+
* See https://developer.mozilla.org/en-US/docs/Web/API/ValidityState for available Validator FlagTypes.
202+
*
203+
* @example
204+
* this.addValidator(
205+
* 'tooLong',
206+
* () => 'This input contains too many characters',
207+
* () => this._value.length > 10
208+
* );
209+
* @method hasValue
210+
* @param {FlagTypes} flagKey the type of validation.
211+
* @param {method} getMessage method to retrieve relevant message. Is executed every time the validator is re-executed.
212+
* @param {method} checkMethod method to determine if this validator should invalidate this form control. Return true if this should prevent submission.
213+
*/
187214
protected addValidator(
188215
flagKey: FlagTypes,
189216
getMessageMethod: () => String,
@@ -225,13 +252,6 @@ export const FormControlMixin = <T extends Constructor<LitElement>>(
225252
updated(changedProperties: Map<string | number | symbol, unknown>) {
226253
super.updated(changedProperties);
227254
this._runValidators();
228-
/*
229-
if(changedProperties.has('pristine')) {
230-
if(changedProperties.get('pristine') === false) {
231-
this._internals.reportValidity();
232-
}
233-
}
234-
*/
235255
}
236256

237257
private _onFormSubmit = () => {

packages/uui-form-validation-message/lib/uui-form-validation-message.element.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import { repeat } from 'lit/directives/repeat.js';
77

88
/**
99
* @element uui-form-validation-message
10-
* @description - Component for displaying one or more validation messages from Form Control within the given scope. Notice: Only supports components that build on the FormControlMixing.
10+
* @description - Component for displaying one or more validation messages from UUI Form Control within the given scope.
11+
* Notice: Only supports components that is build on the FormControlMixing.
1112
* @slot - for button contents
1213
* @slot message - for extras in the messages container
14+
* @see FormControlMixin
1315
*/
1416

1517
@defineElement('uui-form-validation-message')
@@ -77,8 +79,8 @@ export class UUIFormValidationMessageElement extends LitElement {
7779

7880
private _onControlInvalid = (e: UUIFormControlEvent) => {
7981
const ctrl = e.target;
80-
if (ctrl.pristine !== true) {
81-
// This enables any component who does have the pristine property to hide a message. (as well we only want to show messages from fields that are NOT pristine aka. that are dirty or in a from that has been submitted)
82+
if (ctrl.pristine === false) {
83+
// Currently we only show message from components who does have the pristine property. (we only want to show messages from fields that are NOT pristine aka. that are dirty or in a from that has been submitted)
8284
this._messages.set(ctrl, ctrl.validationMessage);
8385
} else {
8486
this._messages.delete(ctrl);

packages/uui-form-validation-message/lib/uui-form-validation-message.story.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ AAAOverview.storyName = 'Overview';
3333
export const ForAnotherElement: Story = () =>
3434
html` <p>
3535
The Form Validation Message element can also display validation messages
36-
from another element than it self. This is done by setting the 'for'
36+
from another scope than it self. This is done by setting the 'for'
3737
attribute.
3838
</p>
3939
<div id="myCustomScope">

packages/uui-form/lib/uui-form.element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class UUIFormElement extends HTMLFormElement {
1818
const isValid = this.checkValidity();
1919

2020
if (!isValid) {
21+
// submit-invalid attribute is used by descendant form controls to check wether submit has been requested without succeeding.
2122
this.setAttribute('submit-invalid', '');
2223
return;
2324
}

0 commit comments

Comments
 (0)