mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 15:05:42 +00:00
Added options to enable live validation and hide field labels
This commit is contained in:
parent
376cc8653a
commit
cd9af7e13f
@ -23,7 +23,9 @@ class UserDefinedForm extends Page {
|
||||
"SubmitButtonText" => "Varchar",
|
||||
"OnCompleteMessage" => "HTMLText",
|
||||
"ShowClearButton" => "Boolean",
|
||||
'DisableSaveSubmissions' => 'Boolean'
|
||||
'DisableSaveSubmissions' => 'Boolean',
|
||||
'EnableLiveValidation' => 'Boolean',
|
||||
'HideFieldLabels' => 'Boolean'
|
||||
);
|
||||
|
||||
/**
|
||||
@ -268,7 +270,9 @@ class UserDefinedForm extends Page {
|
||||
|
||||
$options = new FieldList(
|
||||
new TextField("SubmitButtonText", _t('UserDefinedForm.TEXTONSUBMIT', 'Text on submit button:'), $submit),
|
||||
new CheckboxField("ShowClearButton", _t('UserDefinedForm.SHOWCLEARFORM', 'Show Clear Form Button'), $this->ShowClearButton)
|
||||
new CheckboxField("ShowClearButton", _t('UserDefinedForm.SHOWCLEARFORM', 'Show Clear Form Button'), $this->ShowClearButton),
|
||||
new CheckboxField("EnableLiveValidation", _t('UserDefinedForm.ENABLELIVEVALIDATION', 'Enable live validation')),
|
||||
new CheckboxField("HideFieldLabels", _t('UserDefinedForm.HIDEFIELDLABELS', 'Hide field labels'))
|
||||
);
|
||||
|
||||
$this->extend('updateFormOptions', $options);
|
||||
@ -324,7 +328,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
|
||||
// load the jquery
|
||||
Requirements::javascript(FRAMEWORK_DIR .'/thirdparty/jquery/jquery.js');
|
||||
Requirements::javascript('userforms/thirdparty/jquery-validate/jquery.validate.min.js');
|
||||
Requirements::javascript('userforms/thirdparty/jquery-validate/jquery.validate.js');
|
||||
Requirements::javascript('userforms/javascript/UserForm_frontend.js');
|
||||
}
|
||||
|
||||
@ -484,6 +488,8 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
$rules = array();
|
||||
$validation = array();
|
||||
$messages = array();
|
||||
$onfocusout = "";
|
||||
$hidelabels = "";
|
||||
|
||||
if($this->Fields()) {
|
||||
foreach($this->Fields() as $field) {
|
||||
@ -496,6 +502,12 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
// Enable live validation
|
||||
if($this->EnableLiveValidation) $onfocusout = ", onfocusout : function(element) { this.element(element); }";
|
||||
|
||||
// Hide field labels (use HTML5 placeholder instead)
|
||||
if($this->HideFieldLabels) $hidelabels = '$("#Form_Form label.left").each(function(){$("#"+$(this).attr("for")).attr("placeholder",$(this).text());$(this).remove();});';
|
||||
|
||||
// Set the Form Name
|
||||
$rules = $this->array2json($rules);
|
||||
$messages = $this->array2json($messages);
|
||||
@ -519,7 +531,9 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
,
|
||||
rules:
|
||||
$rules
|
||||
$onfocusout
|
||||
});
|
||||
$hidelabels
|
||||
});
|
||||
})(jQuery);
|
||||
JS
|
||||
@ -685,17 +699,19 @@ JS
|
||||
}
|
||||
}
|
||||
|
||||
Requirements::customScript(<<<JS
|
||||
(function($) {
|
||||
$(document).ready(function() {
|
||||
$default
|
||||
// Only add customScript if $default or $rules is defined
|
||||
if($default || $rules) {
|
||||
Requirements::customScript(<<<JS
|
||||
(function($) {
|
||||
$(document).ready(function() {
|
||||
$default
|
||||
|
||||
$rules
|
||||
})
|
||||
})(jQuery);
|
||||
$rules
|
||||
})
|
||||
})(jQuery);
|
||||
JS
|
||||
, 'UserFormsConditional');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user