Permalink
Browse files

Fixed bugs:

- Fixed issue #13. Fields with property_path = false must be excluded from validation.
- Fixed issue #16. No need to supply second parameter to createForm controller function.
- [cache warmer] Changed the naming of the output javascript file.
	After:
		{{ JSFV(form, true) }} returns  /bundle/jsformvalidation/js/myRoute_myForm.js
	Before:
		{{ JSFV(form, true) }} has returned  /bundle/jsformvalidation/js/myRoute.js
  • Loading branch information...
1 parent 37bf500 commit 7516250e539ed94e465a8094852de7640d0c14c7 Vitaliy Demidov committed Aug 16, 2012
View
@@ -1,3 +1,13 @@
+#2012-08-16
+- Implemented phpunit tests. Fixed composer for travis integration.
+- Fixed issue #13. Fields with property_path = false must be excluded from validation.
+- Fixed issue #16. No need to supply second parameter to createForm controller function.
+- [cache warmer] Changed the naming of the output javascript file.
+ After:
+ {{ JSFV(form, true) }} returns /bundle/jsformvalidation/js/myRoute_myForm.js
+ Before:
+ {{ JSFV(form, true) }} has returned /bundle/jsformvalidation/js/myRoute.js
+
#2012-08-12
- Implemented client-side validation of simple forms which are built manually.
@@ -20,7 +20,7 @@ public function onJsfvPreProcess(PreProcessEvent $event)
$formView = $event->getFormView();
$formValidationGroups = $formView->get('validation_groups', array('Default'));
- $formFields = array_keys($formView->getChildren());
+ $formFields = array_keys($formView->children);
$metadata = $event->getMetaData();
foreach ($formFields as $fieldName) {
@@ -62,8 +62,15 @@ public function getExtendedType()
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
+ $dataClass = $builder->getDataClass();
$subscriber = new AddIdentifierSubscriber($builder->getFormFactory(), $this->getJsfv());
$builder->addEventSubscriber($subscriber);
+ if (!empty($options['validation_groups'])) {
+ $builder->setAttribute('validation_groups', $options['validation_groups']);
+ }
+ if ($dataClass !== null) {
+ $builder->setAttribute('data_class', $dataClass);
+ }
}
/**
@@ -73,14 +80,25 @@ public function buildForm(FormBuilderInterface $builder, array $options)
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
+ $config = $form->getConfig();
// Add validation groups to the view
- if ($form->getConfig()->hasAttribute('validation_groups')) {
- $view->set('validation_groups', $form->getConfig()->getAttribute('validation_groups'));
+ if ($config->hasAttribute('validation_groups')) {
+ $view->set('validation_groups', $config->getAttribute('validation_groups'));
+ }
+ if ($config->hasAttribute('data_class')) {
+ $view->set('data_class', $config->getAttribute('data_class'));
}
// Adds constraints to the view. It comes from simple forms
- if ($form->getConfig()->hasOption('constraints')) {
- $view->set('constraints', $form->getConfig()->getOption('constraints'));
+ if ($config->hasOption('constraints')) {
+ $view->set('constraints', $config->getOption('constraints'));
+ }
+ if ($config->hasOption('property_path')) {
+ // Fields with property_path = false must be excluded from validation
+ $property_path = $config->getOption('property_path');
+ if ($property_path === false) {
+ $view->set('property_path', false);
+ }
}
- $view->set('error_mapping', $form->getConfig()->getOption('error_mapping'));
+ $view->set('error_mapping', $config->getOption('error_mapping'));
}
}
@@ -187,7 +187,8 @@ public function generate(FormView $formView, $overwrite = false)
// Prepare output file
$scriptPath = $this->container->getParameter('apy_js_form_validation.script_directory');
$scriptRealPath = $this->container->getParameter('assetic.write_to').'/'.$scriptPath;
- $scriptFile = strtolower($this->container->get('request')->get('_route')).".js";
+ $formName = $formView->getName() ?: 'form';
+ $scriptFile = strtolower($this->container->get('request')->get('_route')) . "_" . strtolower($formName) . ".js";
if ($overwrite || false === file_exists($scriptRealPath . $scriptFile)) {
// Initializes variables
@@ -201,6 +202,8 @@ public function generate(FormView $formView, $overwrite = false)
$formViewValue = $formView->get('value');
if (is_object($formViewValue)) {
$entityName = get_class($formViewValue);
+ } elseif ($formView->get('data_class') && class_exists($formView->get('data_class'))) {
+ $entityName = $formView->get('data_class');
}
if (isset($entityName)) {
@@ -300,6 +303,8 @@ public function generate(FormView $formView, $overwrite = false)
if (!empty($constraintsTarget)) {
// we look through each field of the form
foreach ($formView->children as $formField) {
+ // Fields with property_path=false must be excluded from validation
+ if ($formField->get('property_path') === false) continue;
// we look for constraints for the field
if (isset($constraintsTarget[$formField->get('name')])) {
$constraintList = isset($entityName) ?
View
@@ -11,7 +11,7 @@ Identifier : `jsfv.pre_process`
- FormView : The Form view object of the form
- ClassMetadata : Metadata of the entity/document used by the form
-Exemple : [Validation groups] (https://github.com/Abhoryo/APYJsFormValidationBundle/blob/master/EventListener/ValidationGroupsListener.php)
+Example : [Validation groups] (https://github.com/Abhoryo/APYJsFormValidationBundle/blob/master/EventListener/ValidationGroupsListener.php)
## Post processing event
@@ -21,4 +21,4 @@ Identifier : `jsfv.post_process`
- FormView : The Form view object of the form
- FieldsConstraints : Compiled Object used to generate the validation script
-Exemple : [Repeated field] (https://github.com/Abhoryo/APYJsFormValidationBundle/blob/master/EventListener/RepeatedFieldListener.php)
+Example : [Repeated field] (https://github.com/Abhoryo/APYJsFormValidationBundle/blob/master/EventListener/RepeatedFieldListener.php)
@@ -47,8 +47,8 @@ Configuration read from root-folder-of-your-app\vendor\apy\jsfv-bundle\APY\JsFor
Time: 9 seconds, Memory: 30.75Mb
-←[30;42m←[2KOK (4 tests, 50 assertions)
-←[0m←[2K
+OK (4 tests, 50 assertions)
+
```
@@ -10,7 +10,7 @@ The twig function JSFV generates the script and returns the path of the script i
will turn into:
```xml
-<script type="text/javascript" src="/bundle/jsformvalidation/js/my_route.js"></script>
+<script type="text/javascript" src="/bundle/jsformvalidation/js/myRoute_myForm.js"></script>
```
The script isn't regenerated if the script already exists.
@@ -27,7 +27,7 @@ JSFV function accepts a boolean argument. Sets to true, the Twig function return
will turn into:
-`/bundle/jsformvalidation/js/my_route.js`
+`/bundle/jsformvalidation/js/myRoute_myForm.js`
So you can use this too:
Oops, something went wrong.

0 comments on commit 7516250

Please sign in to comment.