Skip to content
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

🎨🔢 Set limit to number of characters and possible options on question and list block options #321

Merged
merged 7 commits into from
Feb 28, 2023
Next Next commit
✨ feat: Add option input maxlength validation and error message
Add maxlength variable to option component.
Add custom error message to display on invalid input
  • Loading branch information
royokite committed Feb 23, 2023
commit 33c62bf25198cf98e0d4e2bea65928a885813f42
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
<div [formGroupName]="formGroupNameInput" class="option" fxFlex>
<input [id]="inputUniqueId" [class]="optionClass" [readOnly]="isReadOnly"
[ngClass]="isReadOnly? 'readonly' : ''" formControlName="message"
type="text" placeholder="Click here to edit" fxFlexFill>
type="text" placeholder="Click here to edit" [maxlength]="charMaxlength" [(ngModel)]="optionValue" fxFlexFill>
<span class="length-error" *ngIf="optionValue.length >= charMaxlength">
maximum characters reached
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use multi-lang. Have a look at the below from the login.component.html
image

The translations are added in the files en.json and fr.json

</span>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,32 @@ import { _JsPlumbComponentDecorator } from '../../providers/jsplumb-decorator.fu
templateUrl: './option-input-field.component.html',
styleUrls: ['./option-input-field.component.scss'],
})
export class OptionInputFieldComponent implements OnInit, AfterViewInit
{
export class OptionInputFieldComponent implements OnInit, AfterViewInit {

@Input() blockFormGroup: FormGroup;
@Input() formGroupNameInput: number | string;
@Input() jsPlumb: BrowserJsPlumbInstance;
@Input() optionClass: string;
@Input() isEndpoint: boolean;
@Input() isReadOnly: boolean;
@Input() charMaxlength: number;

inputUniqueId: string;
optionValue: string = "";

constructor() {}
constructor() { }

ngOnInit(): void
{
ngOnInit(): void {
if (this.isEndpoint) {
this.inputUniqueId = `i-${this.formGroupNameInput}-${this.blockFormGroup.value.id}`;
}
}

ngAfterViewInit(): void
{
ngAfterViewInit(): void {
this._decorateInput();
}

private _decorateInput()
{
private _decorateInput() {
let input = document.getElementById(this.inputUniqueId) as Element;
if (this.jsPlumb) {
input = _JsPlumbComponentDecorator(input, this.jsPlumb);
Expand Down