developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #751: 751-jForms-javascript-check-of-secret-control-confirmation-does-not-work.diff

File 751-jForms-javascript-check-of-secret-control-confirmation-does-not-work.diff, 18.7 KB (added by Julien, 13 years ago)
  • trunk/testapp/modules/jelix_tests/tests/jforms.htmllightbuilder.html_cli.php

     
    10041004
    10051005        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10061006        $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" value=""/>', $out);
    1007         $this->assertEqualOrDiff('c = new jFormsControlString(\'passwd\', \'mot de passe\');
     1007        $this->assertEqualOrDiff('c = new jFormsControlSecret(\'passwd\', \'mot de passe\');
    10081008c.errInvalid=\'"mot de passe" field is invalid\';
    10091009jForms.tForm.addControl(c);
    10101010', $this->builder->getJsContent());
     
    10121012        $this->form->setData('passwd','laurent');
    10131013        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10141014        $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" value="laurent"/>', $out);
    1015         $this->assertEqualOrDiff('c = new jFormsControlString(\'passwd\', \'mot de passe\');
     1015        $this->assertEqualOrDiff('c = new jFormsControlSecret(\'passwd\', \'mot de passe\');
    10161016c.errInvalid=\'"mot de passe" field is invalid\';
    10171017jForms.tForm.addControl(c);
    10181018', $this->builder->getJsContent());
     
    10201020        $ctrl->setReadOnly(true);
    10211021        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10221022        $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" class=" jforms-readonly" value="laurent"/>', $out);
    1023         $this->assertEqualOrDiff('c = new jFormsControlString(\'passwd\', \'mot de passe\');
     1023        $this->assertEqualOrDiff('c = new jFormsControlSecret(\'passwd\', \'mot de passe\');
    10241024c.errInvalid=\'"mot de passe" field is invalid\';
    10251025jForms.tForm.addControl(c);
    10261026', $this->builder->getJsContent());
     
    10301030        $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_passwd" title="ceci est un tooltip">mot de passe</label>', $out);
    10311031        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10321032        $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" value="laurent"/>', $out);
    1033         $this->assertEqualOrDiff('c = new jFormsControlString(\'passwd\', \'mot de passe\');
     1033        $this->assertEqualOrDiff('c = new jFormsControlSecret(\'passwd\', \'mot de passe\');
    10341034c.errInvalid=\'"mot de passe" field is invalid\';
    10351035jForms.tForm.addControl(c);
    10361036', $this->builder->getJsContent());
     
    10391039        $ctrl->datatype->addFacet('maxLength',10);
    10401040        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10411041        $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" maxlength="10" value="laurent"/>', $out);
    1042         $this->assertEqualOrDiff('c = new jFormsControlString(\'passwd\', \'mot de passe\');
     1042        $this->assertEqualOrDiff('c = new jFormsControlSecret(\'passwd\', \'mot de passe\');
    10431043c.maxLength = \'10\';
    10441044c.minLength = \'5\';
    10451045c.errInvalid=\'"mot de passe" field is invalid\';
     
    10581058
    10591059        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10601060        $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" value=""/>', $out);
    1061         $this->assertEqualOrDiff('c.confirmField = new jFormsControlSecretConfirm(\'passwd_confirm_confirm\', \'confirmation mot de passe\');
     1061        $this->assertEqualOrDiff('c = new jFormsControlConfirm(\'passwd_confirm\', \'confirmation mot de passe\');
     1062c.errInvalid=\'"confirmation mot de passe" field is invalid\';
     1063jForms.tForm.addControl(c);
    10621064', $this->builder->getJsContent());
    10631065
     1066        $ctrl->required = true;
     1067        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
     1068        $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" class=" jforms-required" value=""/>', $out);
     1069        $this->assertEqualOrDiff('c = new jFormsControlConfirm(\'passwd_confirm\', \'confirmation mot de passe\');
     1070c.required = true;
     1071c.errRequired=\'"confirmation mot de passe" field is required\';
     1072c.errInvalid=\'"confirmation mot de passe" field is invalid\';
     1073jForms.tForm.addControl(c);
     1074', $this->builder->getJsContent());
     1075        $ctrl->required = false;
    10641076
     1077
    10651078        $ctrl->setReadOnly(true);
    10661079        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10671080        $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" readonly="readonly" class=" jforms-readonly" value=""/>', $out);
    1068         $this->assertEqualOrDiff('c.confirmField = new jFormsControlSecretConfirm(\'passwd_confirm_confirm\', \'confirmation mot de passe\');
     1081        $this->assertEqualOrDiff('c = new jFormsControlConfirm(\'passwd_confirm\', \'confirmation mot de passe\');
     1082c.errInvalid=\'"confirmation mot de passe" field is invalid\';
     1083jForms.tForm.addControl(c);
    10691084', $this->builder->getJsContent());
    10701085
    10711086
     
    10741089        $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_passwd_confirm" title="ceci est un tooltip">confirmation mot de passe</label>', $out);
    10751090        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10761091        $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);
    1077         $this->assertEqualOrDiff('c.confirmField = new jFormsControlSecretConfirm(\'passwd_confirm_confirm\', \'confirmation mot de passe\');
     1092        $this->assertEqualOrDiff('c = new jFormsControlConfirm(\'passwd_confirm\', \'confirmation mot de passe\');
     1093c.errInvalid=\'"confirmation mot de passe" field is invalid\';
     1094jForms.tForm.addControl(c);
    10781095', $this->builder->getJsContent());
    10791096
    10801097    }
  • trunk/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html_cli.php

     
    10071007
    10081008        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10091009        $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" value=""/>', $out);
    1010         $this->assertEqualOrDiff('c = new jFormsJQControlString(\'passwd\', \'mot de passe\');
     1010        $this->assertEqualOrDiff('c = new jFormsJQControlSecret(\'passwd\', \'mot de passe\');
    10111011c.errInvalid=\'"mot de passe" field is invalid\';
    10121012jFormsJQ.tForm.addControl(c);
    10131013', $this->builder->getJsContent());
     
    10151015        $this->form->setData('passwd','laurent');
    10161016        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10171017        $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" value="laurent"/>', $out);
    1018         $this->assertEqualOrDiff('c = new jFormsJQControlString(\'passwd\', \'mot de passe\');
     1018        $this->assertEqualOrDiff('c = new jFormsJQControlSecret(\'passwd\', \'mot de passe\');
    10191019c.errInvalid=\'"mot de passe" field is invalid\';
    10201020jFormsJQ.tForm.addControl(c);
    10211021', $this->builder->getJsContent());
     
    10231023        $ctrl->setReadOnly(true);
    10241024        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10251025        $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" class=" jforms-readonly" value="laurent"/>', $out);
    1026         $this->assertEqualOrDiff('c = new jFormsJQControlString(\'passwd\', \'mot de passe\');
     1026        $this->assertEqualOrDiff('c = new jFormsJQControlSecret(\'passwd\', \'mot de passe\');
    10271027c.errInvalid=\'"mot de passe" field is invalid\';
    10281028jFormsJQ.tForm.addControl(c);
    10291029', $this->builder->getJsContent());
     
    10331033        $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_passwd" title="ceci est un tooltip">mot de passe</label>', $out);
    10341034        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10351035        $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" value="laurent"/>', $out);
    1036         $this->assertEqualOrDiff('c = new jFormsJQControlString(\'passwd\', \'mot de passe\');
     1036        $this->assertEqualOrDiff('c = new jFormsJQControlSecret(\'passwd\', \'mot de passe\');
    10371037c.errInvalid=\'"mot de passe" field is invalid\';
    10381038jFormsJQ.tForm.addControl(c);
    10391039', $this->builder->getJsContent());
     
    10421042        $ctrl->datatype->addFacet('maxLength',10);
    10431043        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10441044        $this->assertEqualOrDiff('<input type="password" name="passwd" id="'.$this->formname.'_passwd" readonly="readonly" title="ceci est un tooltip" class=" jforms-readonly" maxlength="10" value="laurent"/>', $out);
    1045         $this->assertEqualOrDiff('c = new jFormsJQControlString(\'passwd\', \'mot de passe\');
     1045        $this->assertEqualOrDiff('c = new jFormsJQControlSecret(\'passwd\', \'mot de passe\');
    10461046c.maxLength = \'10\';
    10471047c.minLength = \'5\';
    10481048c.errInvalid=\'"mot de passe" field is invalid\';
     
    10611061
    10621062        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10631063        $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" value=""/>', $out);
    1064         $this->assertEqualOrDiff('c.confirmField = new jFormsJQControlSecretConfirm(\'passwd_confirm_confirm\', \'confirmation mot de passe\');
     1064        $this->assertEqualOrDiff('c = new jFormsJQControlConfirm(\'passwd_confirm\', \'confirmation mot de passe\');
     1065c.errInvalid=\'"confirmation mot de passe" field is invalid\';
     1066jFormsJQ.tForm.addControl(c);
    10651067', $this->builder->getJsContent());
    10661068
     1069        $ctrl->required = true;
     1070        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
     1071        $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" class=" jforms-required" value=""/>', $out);
     1072        $this->assertEqualOrDiff('c = new jFormsJQControlConfirm(\'passwd_confirm\', \'confirmation mot de passe\');
     1073c.required = true;
     1074c.errRequired=\'"confirmation mot de passe" field is required\';
     1075c.errInvalid=\'"confirmation mot de passe" field is invalid\';
     1076jFormsJQ.tForm.addControl(c);
     1077', $this->builder->getJsContent());
     1078        $ctrl->required = false;
    10671079
     1080
    10681081        $ctrl->setReadOnly(true);
    10691082        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10701083        $this->assertEqualOrDiff('<input type="password" name="passwd_confirm" id="'.$this->formname.'_passwd_confirm" readonly="readonly" class=" jforms-readonly" value=""/>', $out);
    1071         $this->assertEqualOrDiff('c.confirmField = new jFormsJQControlSecretConfirm(\'passwd_confirm_confirm\', \'confirmation mot de passe\');
     1084        $this->assertEqualOrDiff('c = new jFormsJQControlConfirm(\'passwd_confirm\', \'confirmation mot de passe\');
     1085c.errInvalid=\'"confirmation mot de passe" field is invalid\';
     1086jFormsJQ.tForm.addControl(c);
    10721087', $this->builder->getJsContent());
    10731088
    10741089
     
    10771092        $this->assertEqualOrDiff('<label class="jforms-label" for="'.$this->formname.'_passwd_confirm" title="ceci est un tooltip">confirmation mot de passe</label>', $out);
    10781093        ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean();
    10791094        $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);
    1080         $this->assertEqualOrDiff('c.confirmField = new jFormsJQControlSecretConfirm(\'passwd_confirm_confirm\', \'confirmation mot de passe\');
     1095        $this->assertEqualOrDiff('c = new jFormsJQControlConfirm(\'passwd_confirm\', \'confirmation mot de passe\');
     1096c.errInvalid=\'"confirmation mot de passe" field is invalid\';
     1097jFormsJQ.tForm.addControl(c);
    10811098', $this->builder->getJsContent());
    10821099
    10831100    }
  • trunk/lib/jelix-www/js/jforms_light.js

     
    252252};
    253253
    254254/**
    255  * control with optional confirmation string
     255 * control for secret input
    256256 */
    257257function jFormsControlSecret(name, label) {
    258258    this.name = name;
     
    261261    this.errInvalid = '';
    262262    this.errRequired = '';
    263263    this.help='';
    264     this.confirmField = null;
    265264    this.minLength = -1;
    266265    this.maxLength = -1;
    267266};
     
    270269        return false;
    271270    if(this.maxLength != -1 && val.length > this.maxLength)
    272271        return false;
    273 
    274     if(this.confirmField){
    275         var val2 = jfrm.getValue(jfrm.frmElt.elements[this.confirmField.name]);
    276         if(val != val2){
    277             jfrm.tForm.errorDecorator.addError(this.confirmField, 2);
    278             return false;
    279         }
    280     }
    281272    return true;
    282273};
    283 function jFormsControlSecretConfirm(name, label) {
     274
     275/**
     276 * confirm control
     277 */
     278function jFormsControlConfirm(name, label) {
    284279    this.name = name;
    285280    this.label = label;
     281    this.required = false;
    286282    this.errInvalid = '';
    287283    this.errRequired = '';
    288284    this.help='';
    289     this.minLength = -1;
    290     this.maxLength = -1;
     285    this._masterControl = jForms.tForm.getControl(name.replace(/_confirm$/,''));
    291286};
     287jFormsControlConfirm.prototype.check = function(val, jfrm) {
     288    if(jfrm.getValue(jfrm.frmElt.elements[this._masterControl.name]) !== val)
     289        return false;
     290    return true;
     291}
    292292
    293293/**
    294294 * control with boolean
  • trunk/lib/jelix-www/js/jforms_jquery.js

     
    243243};
    244244
    245245/**
    246  * control with optional confirmation string
     246 * control for secret input
    247247 */
    248248function jFormsJQControlSecret(name, label) {
    249249    this.name = name;
     
    252252    this.errInvalid = '';
    253253    this.errRequired = '';
    254254    this.help='';
    255     this.confirmField = null;
    256255    this.minLength = -1;
    257256    this.maxLength = -1;
    258257};
     
    261260        return false;
    262261    if(this.maxLength != -1 && val.length > this.maxLength)
    263262        return false;
    264 
    265     if(this.confirmField){
    266         var val2 = jfrm.getValue(jfrm.frmElt.elements[this.confirmField.name]);
    267         if(val != val2){
    268             jfrm.tForm.errorDecorator.addError(this.confirmField, 2);
    269             return false;
    270         }
    271     }
    272263    return true;
    273264};
    274 function jFormsJQControlSecretConfirm(name, label) {
     265
     266/**
     267 * confirm control
     268 */
     269function jFormsJQControlConfirm(name, label) {
    275270    this.name = name;
    276271    this.label = label;
     272    this.required = false;
    277273    this.errInvalid = '';
    278274    this.errRequired = '';
    279275    this.help='';
    280     this.minLength = -1;
    281     this.maxLength = -1;
     276    this._masterControl = jFormsJQ.tForm.getControl(name.replace(/_confirm$/,''));
    282277};
     278jFormsJQControlConfirm.prototype.check = function(val, jfrm) {
     279    if(jfrm.getValue(jfrm.frmElt.elements[this._masterControl.name]) !== val)
     280        return false;
     281    return true;
     282}
    283283
    284284/**
    285285 * control with boolean
  • trunk/lib/jelix/plugins/jforms/html/html.jformsbuilder.php

     
    476476    }
    477477
    478478    protected function jsSecret($ctrl) {
    479         $this->jsTextarea($ctrl);
     479        $this->jsContent .="c = new jFormsJQControlSecret('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
     480
     481        $maxl= $ctrl->datatype->getFacet('maxLength');
     482        if($maxl !== null)
     483            $this->jsContent .="c.maxLength = '$maxl';\n";
     484
     485        $minl= $ctrl->datatype->getFacet('minLength');
     486        if($minl !== null)
     487            $this->jsContent .="c.minLength = '$minl';\n";
     488
     489        $this->commonJs($ctrl);
    480490    }
    481491
    482492    protected function outputSecretconfirm($ctrl, $id, $class, $readonly, $hint) {
     
    485495    }
    486496
    487497    protected function jsSecretconfirm($ctrl) {
    488         // we assume that a secret confirm control is just after a secret control in the list of controls
    489         $this->jsContent .= "c.confirmField = new jFormsJQControlSecretConfirm('".$ctrl->ref."_confirm', ".$this->escJsStr($ctrl->label).");\n";
     498        $this->jsContent .="c = new jFormsJQControlConfirm('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
     499        $this->commonJs($ctrl);
    490500    }
    491501
    492502    protected function outputOutput($ctrl, $id, $class, $readonly, $hint) {
  • trunk/lib/jelix/plugins/jforms/htmllight/htmllight.jformsbuilder.php

     
    474474    }
    475475
    476476    protected function jsSecret($ctrl) {
    477         $this->jsTextarea($ctrl);
     477        $this->jsContent .="c = new jFormsControlSecret('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
     478
     479        $maxl= $ctrl->datatype->getFacet('maxLength');
     480        if($maxl !== null)
     481            $this->jsContent .="c.maxLength = '$maxl';\n";
     482
     483        $minl= $ctrl->datatype->getFacet('minLength');
     484        if($minl !== null)
     485            $this->jsContent .="c.minLength = '$minl';\n";
     486
     487        $this->commonJs($ctrl);
    478488    }
    479489
    480490    protected function outputSecretconfirm($ctrl, $id, $class, $readonly, $hint) {
     
    483493    }
    484494
    485495    protected function jsSecretconfirm($ctrl) {
    486         // we assume that a secret confirm control is just after a secret control in the list of controls
    487         $this->jsContent .= "c.confirmField = new jFormsControlSecretConfirm('".$ctrl->ref."_confirm', ".$this->escJsStr($ctrl->label).");\n";
     496        $this->jsContent .="c = new jFormsControlConfirm('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
     497        $this->commonJs($ctrl);
    488498    }
    489499
    490500    protected function outputOutput($ctrl, $id, $class, $readonly, $hint) {