I need to be Create one form using PCF in that some password validation i need to give but i write code in index.ts file it showing error
Suggest:- Kindly provide me Code where i have to mentioned the validation code
plz check my below code :-
import {IInputs, IOutputs} from "./generated/ManifestTypes";
export class ValidPass implements ComponentFramework.StandardControl<IInputs, IOutputs> {
/** variable for HTML elements */
private _FormElement: HTMLInputElement;
private _submitButton:HTMLElement;
// private _PasswordCheckLabel:HTMLElement;
/** variable for Form Properties*/
private _UserId: string;
private _Password:string;
private _PasswordCheck:string;
/** event variables */
private _submitClicked:EventListenerOrEventListenerObject;
// private _PasswordCheckOnKeypressed:EventListener;
private _context: ComponentFramework.Context<IInputs>;
// private _notifyOutputChanged: () => void;
private _container: HTMLDivElement;
constructor()
{
}
/**
* Used to initialize the control instance. Controls can kick off remote server calls and other initialization actions here.
* Data-set values are not initialized here, use updateView.
* @param context The entire property bag available to control via Context Object; It contains values as set up by the customizer mapped to property names defined in the manifest, as well as utility functions.
* @param notifyOutputChanged A callback method to alert the framework that the control has new outputs ready to be retrieved asynchronously.
* @param state A piece of data that persists in one session for a single user. Can be set at any point in a controls life cycle by calling 'setControlState' in the Mode interface.
* @param container If a control is marked control-type='starndard', it will receive an empty div element within which it can render its content.
*/
public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container:HTMLDivElement)
{
this._context = context;
// this._notifyOutputChanged = notifyOutputChanged;
this._container = container;
this._submitClicked = this.submitClick.bind(this);
// this._PasswordCheckOnKeypressed = this._PasswordCheckOnKeypressed.bind(this);
this._FormElement = document.createElement("input");
// this._FormElement.addEventListener("check", this._PasswordCheckOnKeypressed);
this._FormElement = document.createElement("input");
this._FormElement.setAttribute("Value", "UserId");
this._FormElement.setAttribute("type","Password");
this._FormElement.setAttribute("lenght","PasswordCheck");
// this._FormElement.addEventListener("check", this._PasswordCheckOnKeypressed);
//this._PasswordCheckLabel = document.createElement("input");
//this._PasswordCheckLabel.setAttribute("Value","PasswordCheck");
//this._PasswordCheckLabel.setAttribute("type","PasswordCheck");
//this._PasswordCheckLabel.addEventListener("check",this._PasswordCheckOnKeypressed);
this._submitButton = document.createElement("input");
this._submitButton.setAttribute("Value", "Submit");
this._submitButton.setAttribute("Type","Submit");
this._submitButton.addEventListener("click", this._submitClicked);
//this._container.appendChild(this._FormElement);
this._container.appendChild(this._submitButton);
// this._container.appendChild(this._PasswordCheckLabel);
}
/**
* Called when any value in the property bag has changed. This includes field values, data-sets, global values such as container height and width, offline status, control metadata values such as label, visible, etc.
* @param context The entire property bag available to control via Context Object; It contains values as set up by the customizer mapped to names defined in the manifest, as well as utility functions
*/
public updateView(context: ComponentFramework.Context<IInputs>): void
{
// Add code to update control view
}
/**
* It is called by the framework prior to a control receiving new data.
* @returns an object based on nomenclature defined in manifest, expecting object[s] for property marked as “bound” or “output”
*/
public getOutputs(): IOutputs
{
return {
UserId:this._UserId,
Password:this._Password
};
}
/**
* Called when the control is to be removed from the DOM tree. Controls should use this call for cleanup.
* i.e. cancelling any pending remote calls, removing listeners, etc.
*/
public destroy(): void
{
// Add code to cleanup control if necessary
}
================== public submitClick(evt:Event): void ================
{
debugger;
var Password= this._FormElement;
// Validate lowercase letters
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(this._FormElement.value))
{
alert("correct password")
}
else {
alert("You have entered an invalid email address!")
}
}
}
*This post is locked for comments
What error you are getting ?
If I m understanding you correctly, you can add validation in "updateView".
Alternatively you can add a JS event handler for your "input" and register a JS event handler may be something like "onblur" and do validation there.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156