Hello,
I'd like to add an custom validation in my forms using JavaScript and DataExtension. With 'normal' fields everything works fine, but when I try to do the same thing with DataExtension, JavaScript can't see variable.
My code looks like this:
SiteConfigExtension.php:
class SiteConfigExtension extends DataExtension
{
private static $db = array(
'MainQuoteModal__Message' => 'Text',
);
}
HomePage.php Controller
public function init() {
parent::init();
Requirements::javascriptTemplate($this->ThemeDir().'/js/script.js', array(
'MainQuoteModal__Message' => $this->MainQuoteModal__Message
));
}
Script.js
var validationObj = {
firstName: {
identifier: 'first-name',
rules: [{
type: 'empty',
prompt: '(my variable)'
}]
}
};
Since I need to add 'SiteConfig' before any field name in my template I don't how to use this in my script.js
I've tried:
prompt: '$MainQuoteModal__Message'
prompt: '$SiteConfig.MainQuoteModal__Message'
prompt: '$SiteConfig+MainQuoteModal__Message'
but none of the works here. I think JS need to 'somehow' recognize "SiteConfig" but I don't actually know how to write that.
UPDATE:
I've met another problem, this custom validation works only in my HomePage and supposed to work on every page.
Any help will be appreciated.
Cheers,
Darek.