Changeset 1028 for branches

Show
Ignore:
Timestamp:
07/19/08 15:53:48 (5 months ago)
Author:
laurentj
Message:

ticket #564: finished to implement <choice> in jforms

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/experimental/jforms-groups/lib/jelix-www/design/jform.css

    r906 r1028  
    77.jforms-label {} 
    88.jforms-value {} 
     9.jforms-readonly { color:#aaa; } 
    910 
    1011span.jforms-required, label.jforms-required { font-weight:bold; } 
  • branches/experimental/jforms-groups/lib/jelix-www/js/jforms.js

    r994 r1028  
    150150            frm.helpDecorator.show(ctrl.help); 
    151151        } 
     152    }, 
     153 
     154    hasClass: function (elt,clss) { 
     155        return elt.className.match(new RegExp('(\\s|^)'+clss+'(\\s|$)')); 
     156    }, 
     157    addClass: function (elt,clss) { 
     158        if (!this.hasClass(elt,clss)) elt.className += " "+clss; 
     159    }, 
     160    removeClass: function (elt,clss) { 
     161        if (this.hasClass(elt,clss)) { 
     162            elt.className = elt.className.replace(new RegExp('(\\s|^)'+clss+'(\\s|$)'),' '); 
     163        } 
    152164    } 
    153165}; 
     
    166178    addControl : function(ctrl){ 
    167179        this.controls.push(ctrl); 
     180        ctrl.formName = this.name; 
    168181    }, 
    169182 
     
    174187    setHelpDecorator : function (decorator){ 
    175188        this.helpDecorator = decorator; 
     189    }, 
     190    getControl : function(aControlName) { 
     191        var ctrls = this.controls; 
     192        for(var i=0; i < ctrls.length; i++){ 
     193            if (ctrls[i].name == aControlName) { 
     194                return ctrls[i]; 
     195            } 
     196        } 
     197        return null; 
    176198    } 
    177199}; 
     
    535557    this.items = {}; 
    536558}; 
    537 jFormsControlChoice.prototype.addControl = function (ctrl, itemValue) { 
    538     if(this.items[itemValue] == undefined) 
    539         this.items[itemValue] = []; 
    540     this.items[itemValue].push(ctrl); 
    541 }; 
    542 jFormsControlChoice.prototype.check = function (val, jfrm) { 
    543     if(this.items[val] == undefined) 
    544         return false; 
    545  
    546     var list = this.items[val]; 
    547     for(var i=0; i < list.length; i++) { 
    548         var val2 = jfrm.getValue(jfrm.frmElt.elements[list[i].name]); 
    549  
    550         if (val2 == '') { 
    551             if (list[i].required) { 
    552                 jfrm.tForm.errorDecorator.addError(list[i], 1); 
    553             } 
    554         } else if (!list[i].check(val2, jfrm)) { 
    555             jfrm.tForm.errorDecorator.addError(list[i], 2); 
    556         } 
    557     } 
    558     return true; 
    559 }; 
     559jFormsControlChoice.prototype = { 
     560    addControl : function (ctrl, itemValue) { 
     561        if(this.items[itemValue] == undefined) 
     562            this.items[itemValue] = []; 
     563        this.items[itemValue].push(ctrl); 
     564    }, 
     565    check : function (val, jfrm) { 
     566        if(this.items[val] == undefined) 
     567            return false; 
     568 
     569        var list = this.items[val]; 
     570        for(var i=0; i < list.length; i++) { 
     571            var val2 = jfrm.getValue(jfrm.frmElt.elements[list[i].name]); 
     572 
     573            if (val2 == '') { 
     574                if (list[i].required) { 
     575                    jfrm.tForm.errorDecorator.addError(list[i], 1); 
     576                } 
     577            } else if (!list[i].check(val2, jfrm)) { 
     578                jfrm.tForm.errorDecorator.addError(list[i], 2); 
     579            } 
     580        } 
     581        return true; 
     582    }, 
     583    activate : function (val) { 
     584        var frmElt = document.getElementById(this.formName); 
     585        for(var j in this.items) { 
     586            var list = this.items[j]; 
     587            for(var i=0; i < list.length; i++) { 
     588                var elt = frmElt.elements[list[i].name]; 
     589                if (val == j) { 
     590                    elt.removeAttribute("readonly"); 
     591                    jForms.removeClass(elt, "jforms-readonly"); 
     592                } else { 
     593                    elt.setAttribute("readonly", "readonly"); 
     594                    jForms.addClass(elt, "jforms-readonly"); 
     595                } 
     596            } 
     597        } 
     598    } 
     599
    560600 
    561601 
  • branches/experimental/jforms-groups/lib/jelix/forms/jFormsControl.class.php

    r1022 r1028  
    628628    } 
    629629 
    630  
    631630    function setData($value) { 
    632631        parent::setData($value); 
  • branches/experimental/jforms-groups/lib/jelix/plugins/jforms/html/html.jformsbuilder.php

    r994 r1028  
    161161        $class = ($ctrl->required == false || $ro?'':' jforms-required'); 
    162162        $class.= (isset($this->_form->getContainer()->errors[$ctrl->ref]) ?' jforms-error':''); 
     163        $class.= ($ro && $ctrl->type != 'captcha'?' jforms-readonly':''); 
     164        $readonly = ($ro?' readonly="readonly"':''); 
    163165        if($class !='') $class = ' class="'.$class.'"'; 
    164         $readonly = ($ro?' readonly="readonly"':''); 
    165166        $hint = ($ctrl->hint == ''?'':' title="'.htmlspecialchars($ctrl->hint).'"'); 
    166  
    167167        $this->{'output'.$ctrl->type}($ctrl, $id, $class, $readonly, $hint); 
    168  
    169168        $this->outputHelp($ctrl); 
    170169    } 
     
    388387        foreach( $ctrl->items as $itemName=>$listctrl){ 
    389388            echo '<li><label><input type="radio"',$id,$i,'" value="',htmlspecialchars($itemName),'"'; 
    390             echo ($itemName==$value?' checked="checked"':''),$readonly,$this->_endt; 
     389            echo ($itemName==$value?' checked="checked"':''),$readonly; 
     390            echo ' onclick="jForms.getForm(\'',$this->_name,'\').getControl(\'',$ctrl->ref,'\').activate(\'',$itemName,'\')"', $this->_endt; 
    391391            echo htmlspecialchars($ctrl->itemsNames[$itemName]),'</label> '; 
    392392 
     
    394394                if(!$this->_form->isActivated($ref)) continue; 
    395395                echo ' <span class="jforms-item-controls">'; 
     396                // we remove readonly status so when a user change the choice and  
     397                // javascript is deactivated, it can still change the value of the control 
     398                $ro = $c->isReadOnly() && $readonly != ''; 
     399                if($ro) $c->setReadOnly(false); 
    396400                $this->outputControlLabel($c); 
    397401                echo ' '; 
    398402                $this->outputControl($c); 
     403                if($ro) $c->setReadOnly($ro); 
    399404                echo "</span>\n"; 
    400405            } 
     
    403408        } 
    404409        echo "</ul>\n"; 
     410 
     411        echo '<script type="text/javascript"> 
     412//<![CDATA[ 
     413jForms.getForm("',$this->_name,'").getControl("',$ctrl->ref,'").activate("',$value,'"); 
     414//]]> 
     415</script>'; 
    405416    } 
    406417 
  • branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html_cli.php

    r966 r1028  
    105105        $ctrl->required=false; 
    106106        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    107         $this->assertEqualOrDiff('<input type="text" name="input1" id="'.$this->formname.'_input1" readonly="readonly" value="laurent"/>', $out); 
     107        $this->assertEqualOrDiff('<input type="text" name="input1" id="'.$this->formname.'_input1" readonly="readonly" class=" jforms-readonly" value="laurent"/>', $out); 
    108108 
    109109        $ctrl->setReadOnly(false); 
     
    164164        $ctrl->setReadOnly(true); 
    165165        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    166         $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" value="1"/>', $out); 
     166        $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" class=" jforms-readonly" value="1"/>', $out); 
    167167 
    168168        $this->form->setData('chk2', '1'); 
    169169        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    170         $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" checked="checked" value="1"/>', $out); 
     170        $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" class=" jforms-readonly" checked="checked" value="1"/>', $out); 
    171171 
    172172        $ctrl->hint='ceci est un tooltip'; 
     
    175175 
    176176        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    177         $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" title="ceci est un tooltip" checked="checked" value="1"/>', $out); 
     177        $this->assertEqualOrDiff('<input type="checkbox" name="chk2" id="'.$this->formname.'_chk2" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" checked="checked" value="1"/>', $out); 
    178178    } 
    179179 
     
    249249 
    250250        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    251         $result='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.$this->formname.'_choixmultiple_0" value="10" checked="checked" readonly="readonly"/><label for="'.$this->formname.'_choixmultiple_0">foo</label></span>'; 
    252         $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.$this->formname.'_choixmultiple_1" value="11" readonly="readonly"/><label for="'.$this->formname.'_choixmultiple_1">bar</label></span>'; 
    253         $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.$this->formname.'_choixmultiple_2" value="23" checked="checked" readonly="readonly"/><label for="'.$this->formname.'_choixmultiple_2">baz</label></span>'; 
     251        $result='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.$this->formname.'_choixmultiple_0" value="10" checked="checked" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_choixmultiple_0">foo</label></span>'; 
     252        $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.$this->formname.'_choixmultiple_1" value="11" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_choixmultiple_1">bar</label></span>'; 
     253        $result.='<span class="jforms-chkbox jforms-ctl-choixmultiple"><input type="checkbox" name="choixmultiple[]" id="'.$this->formname.'_choixmultiple_2" value="23" checked="checked" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_choixmultiple_2">baz</label></span>'; 
    254254        $this->assertEqualOrDiff($result, $out); 
    255255 
     
    306306 
    307307        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    308         $result='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.$this->formname.'_rbchoixsimple_0" value="10" readonly="readonly"/><label for="'.$this->formname.'_rbchoixsimple_0">foo</label></span>'; 
    309         $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.$this->formname.'_rbchoixsimple_1" value="11" readonly="readonly"/><label for="'.$this->formname.'_rbchoixsimple_1">bar</label></span>'; 
    310         $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.$this->formname.'_rbchoixsimple_2" value="23" checked="checked" readonly="readonly"/><label for="'.$this->formname.'_rbchoixsimple_2">baz</label></span>'; 
     308        $result='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.$this->formname.'_rbchoixsimple_0" value="10" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_rbchoixsimple_0">foo</label></span>'; 
     309        $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.$this->formname.'_rbchoixsimple_1" value="11" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_rbchoixsimple_1">bar</label></span>'; 
     310        $result.='<span class="jforms-radio jforms-ctl-rbchoixsimple"><input type="radio" name="rbchoixsimple" id="'.$this->formname.'_rbchoixsimple_2" value="23" checked="checked" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_rbchoixsimple_2">baz</label></span>'; 
    311311        $this->assertEqualOrDiff($result, $out); 
    312312    } 
     
    358358 
    359359        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    360         $result='<select name="menulist1" id="'.$this->formname.'_menulist1" title="ceci est un tooltip" size="1">'; 
     360        $result='<select name="menulist1" id="'.$this->formname.'_menulist1" title="ceci est un tooltip" class=" jforms-readonly" size="1">'; 
    361361        $result.='<option value=""></option>'; 
    362362        $result.='<option value="10">foo</option>'; 
     
    369369        $this->form->setData('menulist1',"23"); 
    370370        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    371         $result='<select name="menulist1" id="'.$this->formname.'_menulist1" title="ceci est un tooltip" size="1">'; 
     371        $result='<select name="menulist1" id="'.$this->formname.'_menulist1" title="ceci est un tooltip" class=" jforms-readonly" size="1">'; 
    372372        $result.='<option value="10">foo</option>'; 
    373373        $result.='<option value="11">bar</option>'; 
     
    379379        $this->form->setData('menulist1',""); 
    380380        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    381         $result='<select name="menulist1" id="'.$this->formname.'_menulist1" title="ceci est un tooltip" size="1">'; 
     381        $result='<select name="menulist1" id="'.$this->formname.'_menulist1" title="ceci est un tooltip" class=" jforms-readonly" size="1">'; 
    382382        $result.='<option value="" selected="selected"></option>'; 
    383383        $result.='<option value="10">foo</option>'; 
     
    491491 
    492492        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    493         $result='<select name="listbox1" id="'.$this->formname.'_listbox1" size="4">'; 
     493        $result='<select name="listbox1" id="'.$this->formname.'_listbox1" class=" jforms-readonly" size="4">'; 
    494494        $result.='<option value="10">foo</option>'; 
    495495        $result.='<option value="11">bar</option>'; 
     
    604604        $ctrl->setReadOnly(true); 
    605605        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    606         $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" rows="5" cols="40">laurent</textarea>', $out); 
     606        $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" class=" jforms-readonly" rows="5" cols="40">laurent</textarea>', $out); 
    607607 
    608608        $ctrl->hint='ceci est un tooltip'; 
     
    611611 
    612612        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    613         $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" title="ceci est un tooltip" rows="5" cols="40">laurent</textarea>', $out); 
     613        $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" rows="5" cols="40">laurent</textarea>', $out); 
    614614 
    615615        $ctrl->rows=20; 
    616616        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    617         $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" title="ceci est un tooltip" rows="20" cols="40">laurent</textarea>', $out); 
     617        $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" rows="20" cols="40">laurent</textarea>', $out); 
    618618 
    619619        $ctrl->cols=60; 
    620620        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    621         $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" title="ceci est un tooltip" rows="20" cols="60">laurent</textarea>', $out); 
     621        $this->assertEqualOrDiff('<textarea name="textarea1" id="'.$this->formname.'_textarea1" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" rows="20" cols="60">laurent</textarea>', $out); 
    622622 
    623623    } 
     
    640640        $ctrl->setReadOnly(true); 
    641641        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    642         $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" value="laurent"/>', $out); 
     642        $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" class=" jforms-readonly" value="laurent"/>', $out); 
    643643 
    644644        $ctrl->hint='ceci est un tooltip'; 
     
    646646        $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_passwd" title="ceci est un tooltip">mot de passe</label>', $out); 
    647647        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    648         $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" title="ceci est un tooltip" value="laurent"/>', $out); 
     648        $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" value="laurent"/>', $out); 
    649649    } 
    650650    function testOutputSecretConfirm(){ 
     
    661661        $ctrl->setReadOnly(true); 
    662662        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    663         $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" readonly="readonly" value=""/>', $out); 
     663        $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" readonly="readonly" class=" jforms-readonly" value=""/>', $out); 
    664664 
    665665        $ctrl->hint='ceci est un tooltip'; 
     
    667667        $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_passwd_confirm" title="ceci est un tooltip">confirmation mot de passe</label>', $out); 
    668668        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    669         $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" readonly="readonly" title="ceci est un tooltip" value=""/>', $out); 
     669        $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" value=""/>', $out); 
    670670    } 
    671671 
     
    712712        $ctrl->setReadOnly(true); 
    713713        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    714         $this->assertEqualOrDiff('<input type="file" name="upload1" id="'.$this->formname.'_upload1" readonly="readonly" value=""/>', $out); 
     714        $this->assertEqualOrDiff('<input type="file" name="upload1" id="'.$this->formname.'_upload1" readonly="readonly" class=" jforms-readonly" value=""/>', $out); 
    715715 
    716716        $ctrl->hint='ceci est un tooltip'; 
     
    719719 
    720720        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 
    721         $this->assertEqualOrDiff('<input type="file" name="upload1" id="'.$this->formname.'_upload1" readonly="readonly" title="ceci est un tooltip" value=""/>', $out); 
     721        $this->assertEqualOrDiff('<input type="file" name="upload1" id="'.$this->formname.'_upload1" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" value=""/>', $out); 
    722722 
    723723 
     
    888888jelix_wymeditor_default("'.$this->formname.'_contenu","'.$this->formname.'"); 
    889889//]]> 
    890 </script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" rows="5" cols="40">&lt;p&gt;Ceci est un contenu&lt;/p&gt;</textarea>', $out); 
     890</script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" class=" jforms-readonly" rows="5" cols="40">&lt;p&gt;Ceci est un contenu&lt;/p&gt;</textarea>', $out); 
    891891 
    892892        $ctrl->hint='ceci est un tooltip'; 
     
    899899jelix_wymeditor_default("'.$this->formname.'_contenu","'.$this->formname.'"); 
    900900//]]> 
    901 </script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" title="ceci est un tooltip" rows="5" cols="40">&lt;p&gt;Ceci est un contenu&lt;/p&gt;</textarea>', $out); 
     901</script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" rows="5" cols="40">&lt;p&gt;Ceci est un contenu&lt;/p&gt;</textarea>', $out); 
    902902 
    903903        $ctrl->rows=20; 
     
    907907jelix_wymeditor_default("'.$this->formname.'_contenu","'.$this->formname.'"); 
    908908//]]> 
    909 </script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" title="ceci est un tooltip" rows="20" cols="40">&lt;p&gt;Ceci est un contenu&lt;/p&gt;</textarea>', $out); 
     909</script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" rows="20" cols="40">&lt;p&gt;Ceci est un contenu&lt;/p&gt;</textarea>', $out); 
    910910 
    911911        $ctrl->cols=60; 
     
    915915jelix_wymeditor_default("'.$this->formname.'_contenu","'.$this->formname.'"); 
    916916//]]> 
    917 </script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" title="ceci est un tooltip" rows="20" cols="60">&lt;p&gt;Ceci est un contenu&lt;/p&gt;</textarea>', $out); 
     917</script><textarea name="contenu" id="'.$this->formname.'_contenu" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" rows="20" cols="60">&lt;p&gt;Ceci est un contenu&lt;/p&gt;</textarea>', $out); 
    918918 
    919919    } 
  • branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.htmlbuilder2.html_cli.php

    r967 r1028  
    9999        $expected .= '<table class="jforms-table-group" border="0">'."\n"; 
    100100        $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_nom">Your name</label></th>'."\n"; 
    101         $expected .= '<td><input type="text" name="nom" id="'.$this->formname.'_nom" readonly="readonly" value=""/></td></tr>'."\n"; 
     101        $expected .= '<td><input type="text" name="nom" id="'.$this->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></td></tr>'."\n"; 
    102102        $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_prenom">Your firstname</label></th>'."\n"; 
    103         $expected .= '<td><input type="text" name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" value="robert"/></td></tr>'."\n"; 
     103        $expected .= '<td><input type="text" name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></td></tr>'."\n"; 
    104104        $expected .= '<tr><th scope="row"><span class="jforms-label">Vous ĂȘtes </span></th>'."\n"; 
    105         $expected .= '<td><span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_0" value="h" readonly="readonly"/><label for="'.$this->formname.'_sexe_0">un homme</label></span>'; 
    106         $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_1" value="f" readonly="readonly"/><label for="'.$this->formname.'_sexe_1">une femme</label></span>'; 
    107         $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_2" value="no" readonly="readonly"/><label for="'.$this->formname.'_sexe_2">je ne sais pas</label></span></td></tr>'."\n"; 
     105        $expected .= '<td><span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_0" value="h" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_sexe_0">un homme</label></span>'; 
     106        $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_1" value="f" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_sexe_1">une femme</label></span>'; 
     107        $expected .= '<span class="jforms-radio jforms-ctl-sexe"><input type="radio" name="sexe" id="'.$this->formname.'_sexe_2" value="no" readonly="readonly" class=" jforms-readonly"/><label for="'.$this->formname.'_sexe_2">je ne sais pas</label></span></td></tr>'."\n"; 
    108108        $expected .= '<tr><th scope="row"><label class="jforms-label" for="'.$this->formname.'_mail">Votre mail</label></th>'."\n"; 
    109         $expected .= '<td><input type="text" name="mail" id="'.$this->formname.'_mail" readonly="readonly" value=""/></td></tr>'."\n</table></fieldset>"; 
     109        $expected .= '<td><input type="text" name="mail" id="'.$this->formname.'_mail" readonly="readonly" class=" jforms-readonly" value=""/></td></tr>'."\n</table></fieldset>"; 
    110110        ob_start();$this->builder->outputControl($group);$out = ob_get_clean(); 
    111111        $this->assertEqualOrDiff($expected, $out); 
    112112 
    113113    } 
     114 
     115 
     116    function testOutputChoice(){ 
     117 
     118        $choice= new jFormsControlChoice('status'); 
     119        $choice->label='Task Status'; 
     120        $choice->createItem('new','New'); 
     121        $choice->createItem('assigned','Assigned'); 
     122        $choice->createItem('closed','Closed'); 
     123 
     124        $ctrl= new jFormsControlinput('nom'); 
     125        $ctrl->required=true; 
     126        $ctrl->label='Name'; 
     127        $choice->addChildControl($ctrl,'assigned'); 
     128 
     129 
     130        $ctrl= new jFormsControlinput('prenom'); 
     131        $ctrl->defaultValue='robert'; 
     132        $ctrl->label='Firstname'; 
     133        $choice->addChildControl($ctrl,'assigned'); 
     134 
     135        $ctrl= new jFormsControlMenulist('reason'); 
     136        $ctrl->required=true; 
     137        $ctrl->label='Reason '; 
     138        $ctrl->alertRequired='Hey, specify a reason !'; 
     139        $ctrl->datasource= new jFormsStaticDatasource(); 
     140        $ctrl->datasource->data = array( 
     141        'aa'=>'fixed', 
     142        'bb'=>'won t fixed', 
     143        'cc'=>'later', 
     144        ); 
     145        $choice->addChildControl($ctrl,'closed'); 
     146 
     147        $this->form->addControl($choice); 
     148 
     149 
     150        ob_start();$this->builder->outputControlLabel($choice);$out = ob_get_clean(); 
     151        $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_status">Task Status</label>', $out); 
     152 
     153 
     154        $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n"; 
     155        $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_0" value="new" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label> </li>'."\n"; 
     156        $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_1" value="assigned" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>  <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_nom">Name</label> <input type="text" name="nom" id="'.$this->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></span>'."\n"; 
     157        $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_prenom">Firstname</label> <input type="text" name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></span>'."\n"; 
     158        $expected .= '</li>'."\n"; 
     159        $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_2" value="closed" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>  <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_reason">Reason </label> <select name="reason" id="'.$this->formname.'_reason" class=" jforms-required" size="1"><option value="aa">fixed</option><option value="bb">won t fixed</option><option value="cc">later</option></select></span>'."\n"; 
     160        $expected .= '</li>'."\n"; 
     161        $expected .= '</ul>'."\n"; 
     162        $expected .= '<script type="text/javascript">'."\n"; 
     163        $expected .= '//<![CDATA['."\n"; 
     164        $expected .= 'jForms.getForm("").getControl("status").activate("");'."\n"; 
     165        $expected .= '//]]>'."\n"; 
     166        $expected .= '</script>'; 
     167        ob_start();$this->builder->outputControl($choice);$out = ob_get_clean(); 
     168        $this->assertEqualOrDiff($expected, $out); 
     169 
     170        $this->form->getContainer()->data['status']='assigned'; 
     171 
     172        $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n"; 
     173        $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_0" value="new" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label> </li>'."\n"; 
     174        $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_1" value="assigned" checked="checked" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>  <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_nom">Name</label> <input type="text" name="nom" id="'.$this->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></span>'."\n"; 
     175        $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_prenom">Firstname</label> <input type="text" name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></span>'."\n"; 
     176        $expected .= '</li>'."\n"; 
     177        $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_2" value="closed" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>  <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_reason">Reason </label> <select name="reason" id="'.$this->formname.'_reason" class=" jforms-required" size="1"><option value="aa">fixed</option><option value="bb">won t fixed</option><option value="cc">later</option></select></span>'."\n"; 
     178        $expected .= '</li>'."\n"; 
     179        $expected .= '</ul>'."\n"; 
     180        $expected .= '<script type="text/javascript">'."\n"; 
     181        $expected .= '//<![CDATA['."\n"; 
     182        $expected .= 'jForms.getForm("").getControl("status").activate("assigned");'."\n"; 
     183        $expected .= '//]]>'."\n"; 
     184        $expected .= '</script>'; 
     185        ob_start();$this->builder->outputControl($choice);$out = ob_get_clean(); 
     186        $this->assertEqualOrDiff($expected, $out); 
     187 
     188        $this->form->getContainer()->data['status']='new'; 
     189        $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n"; 
     190        $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_0" value="new" checked="checked" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label> </li>'."\n"; 
     191        $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_1" value="assigned" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>  <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_nom">Name</label> <input type="text" name="nom" id="'.$this->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></span>'."\n"; 
     192        $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_prenom">Firstname</label> <input type="text" name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></span>'."\n"; 
     193        $expected .= '</li>'."\n"; 
     194        $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_2" value="closed" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>  <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_reason">Reason </label> <select name="reason" id="'.$this->formname.'_reason" class=" jforms-required" size="1"><option value="aa">fixed</option><option value="bb">won t fixed</option><option value="cc">later</option></select></span>'."\n"; 
     195        $expected .= '</li>'."\n"; 
     196        $expected .= '</ul>'."\n"; 
     197        $expected .= '<script type="text/javascript">'."\n"; 
     198        $expected .= '//<![CDATA['."\n"; 
     199        $expected .= 'jForms.getForm("").getControl("status").activate("new");'."\n"; 
     200        $expected .= '//]]>'."\n"; 
     201        $expected .= '</script>'; 
     202        ob_start();$this->builder->outputControl($choice);$out = ob_get_clean(); 
     203        $this->assertEqualOrDiff($expected, $out); 
     204 
     205        $this->form->getContainer()->data['status']='closed'; 
     206        $expected = '<ul class="jforms-choice jforms-ctl-status" >'."\n"; 
     207        $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_0" value="new" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label> </li>'."\n"; 
     208        $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_1" value="assigned" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>  <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_nom">Name</label> <input type="text" name="nom" id="'.$this->formname.'_nom" readonly="readonly" class=" jforms-readonly" value=""/></span>'."\n"; 
     209        $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="'.$this->formname.'_prenom">Firstname</label> <input type="text" name="prenom" id="'.$this->formname.'_prenom" readonly="readonly" class=" jforms-readonly" value="robert"/></span>'."\n"; 
     210        $expected .= '</li>'."\n"; 
     211        $expected .= '<li><label><input type="radio" name="status" id="'.$this->formname.'_status_2" value="closed" checked="checked" onclick="jForms.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>  <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="'.$this->formname.'_reason">Reason </label> <select name="reason" id="'.$this->formname.'_reason" class=" jforms-required" size="1"><option value="aa">fixed</option><option value="bb">won t fixed</option><option value="cc">later</option></select></span>'."\n"; 
     212        $expected .= '</li>'."\n"; 
     213        $expected .= '</ul>'."\n"; 
     214        $expected .= '<script type="text/javascript">'."\n"; 
     215        $expected .= '//<![CDATA['."\n"; 
     216        $expected .= 'jForms.getForm("").getControl("status").activate("closed");'."\n"; 
     217        $expected .= '//]]>'."\n"; 
     218        $expected .= '</script>'; 
     219        ob_start();$this->builder->outputControl($choice);$out = ob_get_clean(); 
     220        $this->assertEqualOrDiff($expected, $out); 
     221    } 
     222 
     223 
     224 
    114225} 
    115226 
Download in other formats: Unified Diff Zip Archive