Copied!
CloneableInstantiable
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
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
© 2023 Bruce Wells
Search Namespaces \ Classes
Configuration