- Posts: 8
- Thank you received: 0
Add specific validation rules for a custom field
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Just another remark about the existing validation on 'future' or 'past' dates. When selecting a date from the date control, the validation is done correctly but when a user types a date without using the date control, no validation is done. Is that a (known) bug or am I doing something wrong ?
Please Log in or Create an account to join the conversation.
Maybe it's because the date entered is not a valid date and thus the Date js function is not able to understand it and the the test is just skipped ?
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
$size .= ' onChange="'.$this->prefix.$field->field_namekey.$this->suffix.'_checkDate();"';
after the line:
$field->field_options.='", onClose : '.$this->prefix.$field->field_namekey.$this->suffix.'_checkDate, //';
in the file administrator/components/classes/field.php and try again ?
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
It will be released with next version in several weeks.
If you want it now, you can just add the code:
if(!selectedDate){
selObj.value=\'\';
alert(\''.JText::_('INCORRECT_DATE_FORMAT',true).'\');
return false;
}
after the line:
var selectedDate = new Date(selObj.value);
in that same file and it will display an error message when the date doesn't have the correct format.
Also, the line below will have to be added to your translation file:
INCORRECT_DATE_FORMAT="Incorrect date format"
Please Log in or Create an account to join the conversation.
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in .../public_html/administrator/components/com_hikashop/classes/field.php on line 1219
For the rest everything works fine in Firefox and Google Chrome but I tested also on Internet Explorer 7. In this browser, the check on future or past dates doesn't work at all. When selecting a date in the control or typing a date manually, an 'Error on page' occurs.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Besides, I also have a question about the checkout process. In my current checkout process, I see the different parts (as defined in the configuration) and everything works fine but at the end of the checkout process, users have to click the 'next' button. After clicking 'next', a page is displayed that tells them that the order was already submitted. I wonder if there is a possibility to add some confirmation page in between so that users really now that they will already submit the order when pressing the 'next' button. Another option would be that I can change the 'Next' button on the bottom of the checkout page into a button with label 'Submit order'. In that case, no intermediate confirmation is necessary.
Please Log in or Create an account to join the conversation.
stackoverflow.com/questions/3046459/ie-d...ate-with-time-string
Otherwise, it would mean to parse manually the date (really complicated) or use an external JS library like dateJS (easier but still requires work for the library to be integrated into the system).
For the incorrect date, that will require quite some changes. Here is the Display function code which works properly on our end:
function display($field,$value,$map,$inside,$options='',$test=false){
if(empty($field->field_options)) $field->field_options = "%Y-%m-%d";
$format = $field->field_options;
$size = $options . empty($field->field_options) ? '' : ' size="'.$field->field_options.'"';
if(!empty($field->field_options)){
JHTML::_('behavior.mootools');
$processing='';
switch($field->field_options){
case 'future':
$check = 'today>selectedDate';
$message = JText::_('SELECT_DATE_IN_FUTURE',true);
break;
case 'past':
$check = 'today<selectedDate';
$message = JText::_('SELECT_DATE_IN_PAST',true);
break;
}
$js = 'function '.$this->prefix.$field->field_namekey.$this->suffix.'_checkDate(nohide)
{
var selObj = document.getElementById(\''.$this->prefix.$field->field_namekey.$this->suffix.'\');
if(selObj.value=
'\'){return true;
}
var timestamp=Date.parse(selObj.value);
var today=new Date();
if(isNaN(timestamp)!=false){
selObj.value=\'\';
alert(\''.JText::_('INCORRECT_DATE_FORMAT',true).'\');
return false;
}
var selectedDate = new Date(timestamp);
'.$processing.'
if('.$check.'){
selObj.value=\'\';
alert(\''.$message.'\');
}else{
if(!nohide) this.hide();
}
}';
$document = & JFactory::getDocument();
$document->addScriptDeclaration($js);
$size .= ' onChange="'.$this->prefix.$field->field_namekey.$this->suffix.'_checkDate(1);"';
}
return JHTML::_('calendar', $value, $map,$this->prefix.$field->field_namekey.$this->suffix,$format,$size);
}
You can add a confirmation step. Just configure your checkout workflow in the Checkout tab of the configuration for that.
You can also change the next button for a specific step: www.hikashop.com/en/support/forum/4-how-...bel-next-button.html
Please Log in or Create an account to join the conversation.
The code that you have sent works fine in Google Chrome as well as in Firefox but the date control doesn't close anymore after selecting the date. When clicking the x button, nothing happens. It's not blocking as it's still possible to click the next button but it's not optimal and in Internet Explorer, the control doesn't work at all. Here, the user is really blocked because the 'incorrect_date_format' error pops up every time you select a date and the close button doesn't work. Because of this, I'm not sure if this code should be implemented as a global solution in a next release.
Please Log in or Create an account to join the conversation.
For the incorrect date format on IE, as I said, you would have to use a specific date format if you want it to work: %Y/%m/%d
You can configure it in the format option of your custom field.
Please Log in or Create an account to join the conversation.