1: <?php
2: /**
3: * Description of CheckBox
4: *
5: * @author SARTAJ
6: */
7: namespace Sphp\comp\html{
8:
9: class CheckBox extends \Sphp\tools\Control{
10: private $formName = '';
11: private $msgName = '';
12: private $errmsg = '';
13: private $req = false;
14: private $label = "";
15:
16: public function oninit() {
17: $Client = \SphpBase::sphp_request();
18: $this->tagName = "input";
19: $this->setAttribute('type','checkbox');
20: if($this->issubmit){
21: $this->setAttribute('checked', 'checked');
22: }else if($Client->request('chktxt'.$this->name)=='1'){
23: $this->value = '0';
24: $this->setDataBound();
25: }
26: if($this->getAttribute("msgname") != ""){
27: $this->msgName = $this->getAttribute("msgname");
28: }
29:
30: }
31: public function setLabel($param) {
32: $this->label = $param;
33: }
34: public function setErrMsg($msg){
35: $this->errmsg .= '<strong class="alert-danger">' . $msg . '</strong>';
36: setErr($this->name, $msg);
37: }
38: protected function genhelpPropList() {
39: $this->addHelpPropFunList('setForm','Bind with Form JS Event','','$val');
40: $this->addHelpPropFunList('setMsgName','Name Display in placeholder and Error','','$val');
41: $this->addHelpPropFunList('setRequired','Can not submit Empty','','');
42: }
43:
44: public function setForm($val) { $this->formName = $val;}
45: public function setMsgName($val) { $this->msgName = $val; $this->setAttribute('placeholder', $val);}
46: public function setRequired() {
47: if($this->issubmit){
48: if(strlen($this->value) < 1){
49: $this->setErrMsg($this->getAttribute("msgname") .' ' . "Can not submit Empty");
50: }
51: }
52: $this->req = true;
53: }
54:
55: public function onprejsrender(){
56: if($this->formName !='' && $this->req){
57: $jscode = "if(blnSubmit==true && ".$this->getJSValue()."==false){
58: blnSubmit = false ;
59: alert('Please Accept ".$this->msgName."');
60: document.getElementById('$this->name').focus();
61: }";
62: addFooterJSFunctionCode("{$this->formName}_submit", "$this->name",$jscode);
63: }
64: }
65:
66: public function onrender(){
67: if($this->errmsg!=""){
68: $this->setPostTag($this->errmsg);
69: }
70: if($this->getAttribute('class')==''){
71: $this->class = "form-check-input";
72: }
73: $this->setPostTag('<input type="hidden" name="chktxt'.$this->name.'" value="1" />');
74: if($this->label != ""){
75: $this->setPreTag($this->getPreTag() . '<div class="form-check">');
76: $this->setPostTag('<label class="form-check-label" for="'. $this->name .'">
77: '. $this->label .'
78: </label></div>' . $this->getPostTag());
79: }
80:
81: if($this->value != '1'){
82: $this->setAttribute('value', '1');
83: }else{
84: $this->setAttribute('value', '1');
85: $this->setAttribute('checked', 'checked');
86: }
87:
88: }
89:
90:
91: // javascript functions
92: public function getJSValue(){
93: return "document.getElementById('$this->name').checked" ;
94: }
95:
96: public function setJSValue($exp){
97: $jsOut = "document.getElementById('$this->name').checked = $exp;" ;
98: writeGlobal("jsOut",$jsOut);
99: }
100:
101:
102: }
103: }
104: