v1.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace zin;
  3. class input extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'type: string',
  10. 'name?: string',
  11. 'id?: string',
  12. 'class?: string',
  13. 'value?: string',
  14. 'required?: bool',
  15. 'placeholder?: string',
  16. 'autofocus?: bool',
  17. 'autocomplete?: bool=false',
  18. 'disabled?: bool',
  19. 'min?: int' /* type为number时设置min */
  20. );
  21. /**
  22. * @var mixed[]
  23. */
  24. protected static $defaultProps = array
  25. (
  26. 'type' => 'text',
  27. 'class' => 'form-control'
  28. );
  29. protected function build()
  30. {
  31. $props = $this->props->skip('required');
  32. $required = $this->prop('required');
  33. if(!$this->hasProp('id') && isset($props['name'])) $props['id'] = $props['name'];
  34. if(empty($props['id'])) unset($props['id']);
  35. if(is_bool($props['autocomplete'])) $props['autocomplete'] = $props['autocomplete'] ? 'on' : 'off';
  36. return h::input(set($props), $required ? setClass('is-required') : null);
  37. }
  38. }