Recommend this page to a friend! |
PHP Forms Class with HTML Generator and JavaScript Validation | > | PHP Forms Class with HTML Generator and JavaScript Validation package blog | > | How to Show Google Ma... | > | All threads | > | focus in a select multiple on custom... | > | (Un) Subscribe thread alerts |
|
![]() Hi,
I'm here again with a problem in my custom validation class, after hard work I get success in making a custom validation class to my form, one thing I can't fix, when an error occur, the select multiple input does't get focus.I tried in a text input field and it focus on an error, only the select multiple field didn't work out. Do you have any idea what it might be? best regards and thanks one more time. Wilson ------------------------------ <?php /* * * @(#) $Id: form_dadosfalha_validation.php,v 1.0 2012/04/04 - Wilson $ * */ if(!defined("PHP_LIBRARY_CUSTOM_VALIDATION_FORMS")) { define("PHP_LIBRARY_CUSTOM_VALIDATION_FORMS",1); class form_dadosfalha_validation_class extends form_custom_class { var $client_validate=1; var $server_validate=1; var $mgw_a=''; var $qtmgw_a=''; //------------------------------ Function AddInput(&$form, $arguments) { if (!IsSet($arguments['mgw']) || strlen($this->mgw_a=$arguments['mgw']) == 0) return('It was not specified a valid mgw input identifier'); if(!IsSet($arguments['qtmgw']) || strlen($this->qtmgw_a=$arguments['qtmgw']) == 0) return('It was not specified a valid qtmgw input identifier'); //Get the error messages to assign when the inputs are invalid. if(IsSet($arguments['mgwValidationErrorMessage'])) { if(strlen($arguments['mgwValidationErrorMessage']) == 0 ) return('It was not specified a valid mgw validation error message'); $this->mgw_validation_error_message_a=$arguments['mgwValidationErrorMessage']; } return(''); } //------------------------------ Function ValidateInput(&$form) { $qtmgwsel = 0; foreach ($form->GetInputValue("mgw") as $elem) $qtmgwsel = $qtmgwsel + ($elem == 'Selecione' ? 0 : 1 ); $qtmgw = $form->GetInputValue($this->qtmgw_a) == '' ? 0 : $form->GetInputValue($this->qtmgw_a); if ( $qtmgwsel != $qtmgw ) { $form->FlagInvalidInput($this->mgw_a, $this->mgw_validation_error_message_a); return(''); } return(''); } //------------------------------ Function GetJavascriptValidations(&$form, $form_object, &$validations) { if ( strlen($mgw=$form->GetJavascriptInputObject($form_object,$this->mgw_a)) == 0 ) return('it was not possible to retrieve the mgw input Javascript object'); if(strlen($qtmgw=$form->GetJavascriptInputValue($form_object,$this->qtmgw_a)) == 0 ) return('it was not possible to retrieve the qtmgw input Javascript value'); $validations=array(); $validations[]=array( "Commands"=>array( "qtmgw=".$qtmgw, "mgw=".$mgw, "var qtmgwsel = 0", "for (var i = 0; i < mgw.options.length; i++) {", " if ( (mgw.options[i].selected) && (mgw.options[i].text != 'Selecione') ) {", " qtmgwsel = qtmgwsel + 1", " }", "}", ), 'Condition'=>'qtmgw != qtmgwsel', //The condition is a boolean Javascript expression that is true when the input is invalid. 'ErrorMessage'=>$this->mgw_validation_error_message_a, // // Error message associated to the invalid input 'Focus'=>$this->mgw_a //Input that gets the user input focus so the user fixes its value to make the input valid ); return(''); } //------------------------------ Function AddInputPart(&$form) { return(''); } //------------------------------ }; } ?>
![]() It is hard to tell. Does it happen in all browsers? Can you provide a minimal example script so I can try to reproduce the problem?
![]() bingo, in firefox works fine, the problem appears only in IE.
My form is very big and today I can't make a small functional version, but bellow there is more pieces related to the problem. thanks, Wilson $default = explode (", ",$campo_bd['mgw']); ($default[0] == "") ? $default = array("Selecione") : ''; $form->AddInput(array( "TYPE"=>"select", "MULTIPLE"=>1, "NAME"=>"mgw", "ID"=>"mgw", "SELECTED"=> $default, "SIZE"=>10, "OPTIONS"=> $mgw_opcao, "ValidateAsSet"=>1, "ValidationErrorMessage"=>"Mgw inválido", "LABEL"=>"Mgw" )); ...... //Add a custom input that will be used only for validation purposes $error=$form->AddInput(array( 'TYPE'=>'custom', 'ID'=>'validation', 'CustomClass'=>'form_dadosfalha_validation_class', 'mgw'=>'mgw', 'mgwValidationErrorMessage'=>'Mgw: selecione o nome das Mgw de acordo com a quantidade informada no campo de perdas (Quantidade de Mgw).', 'qtmgw'=>'qtmgw', )); ....... ....... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Dados da Falha <?=$modo?></title> <style type="text/css"><!-- .invalid { border-color: #ff0000; background-color: #F8F8F8; } // --></style> </head> <body onload="<?php echo $onload; ?>" bgcolor="white"> <!-- <center><h2>Relatório da Falha </h2></center> --> <right><font color='green' size=1>Preencha os campos abaixo ...</font></right> <hr /> <?php //Compose the form output by including a HTML form template with PHP code interleaved with calls to insert form input field parts in the layout HTML. $form->StartLayoutCapture(); $title="Relatório da Falha"; if ( ($modo=="HIST") || ($modo=="PRESENTE") ) $body_template="form_auto_layout_body.html.php"; elseif ($modo=="FUTURO") $body_template="dadosfalha_body.php"; require("formGeneration/templates/form_frame.html.php"); $form->EndLayoutCapture(); $form->AddInputPart('validation'); // The custom validation input must also be added to the form output, even though it is not a visible input in the form $form->DisplayOutput(); //Output the form using the function named Output. desconecta($banco); ?> </body> </html>
![]() The JavaScript code to give the focus to the invalid input is the same to all browsers. If it does not look like it got the focus, maybe the browser is not showing the presentation of the input in a way that you see clearly.
Maybe it is a matter of using a CSS style definition for the invalid style that the browser actually uses and make the input look differently. Try setting some border color and style properties in the invalid style.
![]() Thank you, as usual your tips are magic, I change the InvalidSTYLE attributes and the IE accepted. I guess that the problema is with the border-color that never change, but it's not a problem, I'm using another way to focus, like background-color.
The flexibility of forms Generation is impressing. |
info at phpclasses dot org
.