Skip to content

Commit f45d742

Browse files
committed
Merge branch 'release/0.6.2'
2 parents 4b1665c + 84ff21d commit f45d742

2 files changed

Lines changed: 34 additions & 12 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "c0ntax/parsley-bundle",
3-
"version": "0.6.1",
3+
"version": "0.6.2",
44
"type": "symfony-bundle",
55
"description": "A bridge between Symfony and Parsley.js",
66
"license": "Apache-2.0",

src/Form/Extension/ParsleyTypeExtension.php

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,19 @@ public function buildView(FormView $view, FormInterface $form, array $options):
6868
$this->getRemoveSymfonyConstraintsFromParsleys($parsleys)
6969
);
7070

71-
$parsleyConstraints = $this->removeFromConstraints(
72-
array_merge(
73-
$this->createParsleyConstraintsFromValidationConstraints($symfonyConstraints, $form),
74-
$this->getDirectivesFromParsleys($parsleys)
75-
),
71+
$parsleyConstraints = array_merge(
72+
$this->createParsleyConstraintsFromValidationConstraints($symfonyConstraints, $form),
73+
$this->getDirectivesFromParsleys($parsleys)
74+
);
75+
76+
$parsleyDirectives = $this->addDefaultDirectives($parsleyConstraints);
77+
78+
$parsleyDirectives = $this->removeFromConstraints(
79+
$parsleyDirectives,
7680
$this->getRemoveParsleyDirectivesFromParsleys($parsleys)
7781
);
7882

79-
$this->addParsleyToView($view, $parsleyConstraints);
83+
$this->addParsleyToView($view, $parsleyDirectives);
8084
}
8185

8286
/**
@@ -103,6 +107,29 @@ public function configureOptions(OptionsResolver $resolver): void
103107
->addAllowedTypes(self::OPTION_NAME, 'array');
104108
}
105109

110+
/**
111+
* @param array $parsleyDirectives
112+
* @return array
113+
*/
114+
private function addDefaultDirectives(array $parsleyDirectives): array
115+
{
116+
$has = [];
117+
foreach ($parsleyDirectives as $parsleyDirective) {
118+
$class = get_class($parsleyDirective);
119+
if (array_key_exists($class, $has)) {
120+
$has[$class]++;
121+
} else {
122+
$has[$class] = 1;
123+
}
124+
}
125+
126+
if (!array_key_exists(Trigger::class, $has) && count($parsleyDirectives) > 0 && $this->getConfig()['field']['trigger'] !== null) {
127+
$parsleyDirectives[] = new Trigger($this->getConfig()['field']['trigger']);
128+
}
129+
130+
return $parsleyDirectives;
131+
}
132+
106133
/**
107134
* @param ParsleyInterface[] $parsleys
108135
* @return DirectiveInterface[]
@@ -230,11 +257,6 @@ private function addParsleyToView(FormView $view, array $directives): void
230257
}
231258
}
232259

233-
if (!$hasTrigger && count($directives) > 0 && $this->getConfig()['field']['trigger'] !== null) {
234-
$trigger = new Trigger($this->getConfig()['field']['trigger']);
235-
$attr = array_merge($attr, $trigger->getViewAttr());
236-
}
237-
238260
if (count($attr) > 0) {
239261
$view->vars['attr'] = array_merge($view->vars['attr'], $attr);
240262
}

0 commit comments

Comments
 (0)