1: <?php
2: /**
3: * Description of Radio
4: *
5: * @author SARTAJ
6: */
7: namespace Sphp\comp\html{
8:
9: class Radio extends \Sphp\tools\Control{
10: private $formName = '';
11: private $msgName = '';
12: private $req = false;
13: private $vals = array();
14: private $valf = '';
15:
16: protected function genhelpPropList() {
17: parent::genhelpPropList();
18: $this->addHelpPropFunList('setForm','Bind with Form JS Event','','$val');
19: $this->addHelpPropFunList('setMsgName','Name Display in placeholder and Error','','$val');
20: $this->addHelpPropFunList('setRequired','Can not submit Empty','','');
21: }
22:
23: public function oninit() {
24: $this->tagName = "input";
25: $this->setAttribute('type', 'radio');
26: }
27:
28: public function oncreate($element){
29: $this->vals[] = $element->getAttribute('value');
30: if($valf==''){
31: $valf = $element->getAttribute('value');
32: }
33: }
34: public function setForm($val) { $this->formName = $val;}
35: public function setMsgName($val) { $this->msgName = $val;}
36: public function setRequired() {
37: if($this->issubmit){
38: if(strlen($this->value) < 1){
39: setErr($this->name,"Can not submit Empty");
40: }
41: }
42: $this->req = true;
43: }
44:
45: public function onprejsrender(){
46: if($this->formName !='' && $this->req){
47: $jscode = "if(blnSubmit==true && ". $this->getJSValue()."==false){blnSubmit = false ; alert('Please Select ". $this->msgName . "'); document.getElementById('" . $this->name ."').focus();}";
48: addFooterJSFunctionCode("{$this->formName}_submit", "$this->name",$jscode);
49: }
50: }
51:
52: public function onrender(){
53: if($this->getAttribute('class')==''){
54: $this->class = "form-control";
55: }
56: $vt = current($this->vals);
57: if($vt == $this->value){
58: $this->setAttribute('checked', 'checked');
59: }else{
60: $this->setAttribute('checked', '');
61: }
62: $this->setAttribute('value', $vt);
63: next($this->vals);
64: }
65:
66:
67: // javascript functions
68: public function getJSValue(){
69: return "document.getElementById('$this->name').checked" ;
70: }
71:
72: public function setJSValue($exp){
73: $jsOut = "document.getElementById('$this->name').checked = $exp;" ;
74: }
75:
76: }
77: }
78: