Guest User

Untitled

a guest
Oct 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import * as React from "react";
  2. import * as Tripetto from "@tripetto/forms-collector";
  3. import { ICheckbox } from "tripetto-forms-checkbox";
  4.  
  5. @Tripetto.node("tripetto-forms-checkbox")
  6. export class Checkbox extends Tripetto.NodeProvider<JSX.Element, ICheckbox> {
  7. public OnRender(instance: Tripetto.Instance, action: Tripetto.Await): JSX.Element {
  8. const checkbox = this.DataAssert<boolean>(instance, "checked");
  9.  
  10. return (
  11. <label>
  12. <input
  13. type="checkbox"
  14. defaultChecked={checkbox.Value}
  15. onChange={(e: React.ChangeEvent<HTMLInputElement>) => (checkbox.Value = e.target.checked)}
  16. />
  17. {this.Node.Props.Name}
  18. </label>
  19. );
  20. }
  21.  
  22. public OnValidate(instance: Tripetto.Instance): boolean {
  23. const checkbox = this.DataAssert<boolean>(instance, "checked");
  24.  
  25. return !checkbox.Slot.Required || checkbox.Value;
  26. }
  27. }
Add Comment
Please, Sign In to add comment