Copied!
Cloneable Instantiable
Methods
public __construct ( string $validatorName , string $javaScriptFunction = '' )
 

Create a custom Abide validator. Steps for use:

  • Give it name. The current class name is a nice default.
  • Provide the JavaScript to do the validation (required). See getJavaScriptTemplate()
  • Call setValidator on \PHPFUI\Input object
  • Add it to the page with addAbideValidator
  • param string $validatorName is the validator name used in HTML markup
  • param string $javaScriptFunction called to do the validation
public getFunctionName () : string
public getJavaScript () : string
 

Returns the JavaScript that is added to the page when addAbideValidator is called

public getValidatorName () : string
public setJavaScript ( string $javaScriptFunction ) : self
Properties
protected bool $addedToPage
protected string $functionName
protected string $javaScript
protected string $validatorName
Methods
protected getJavaScriptTemplate ( string $customJavaScript ) : string
 

Most validation JavaScript follows a standard pattern:

  • Get the element value
  • If the value is empty and not required, don't bother to validate, simply not set and does not need to be set
  • Otherwise, perform some test passed in by $customJavaScript which should return true if it validates, otherwise false

Local variables available to $customJavaScript

  • el: element being validated
  • required: boolean if input is required
  • parent: of el
  • to: el.val()
  • data: value of the data-validatorname attribute
  • from: value of element pointed to by the id data
  • param string $customJavaScript JavaScript using above variables returning true (validates) or false (not valid)
  • return string of JavaScript to be passed to setJavaScript
© 2022 Bruce Wells
Search Namespaces \ Classes
Configuration