-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored rule::depends into rule::conditions
- Loading branch information
Showing
13 changed files
with
559 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,10 @@ | ||
<?php | ||
$finder = Symfony\CS\Finder\DefaultFinder::create() | ||
->in(__DIR__ . '/src') | ||
->in(__DIR__ . '/tests') | ||
; | ||
|
||
return Symfony\CS\Config\Config::create() | ||
->fixers(array( | ||
'encoding', | ||
'linefeed', | ||
'indentation', | ||
'trailing_spaces', | ||
'unused_use', | ||
'visibility', | ||
'short_tag', | ||
'php_closing_tag', | ||
'return', | ||
'braces', | ||
'lowercase_constants', | ||
'lowercase_keywords', | ||
'include', | ||
'function_declaration', | ||
'controls_spaces', | ||
'spaces_cast', | ||
'elseif', | ||
'eof_ending', | ||
'standardize_not_equal', | ||
'new_with_braces' | ||
)) | ||
->level(Symfony\CS\FixerInterface::PSR2_LEVEL) | ||
->finder($finder) | ||
; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
namespace Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\Condition; | ||
|
||
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleCondition; | ||
use Boekkooi\Bundle\JqueryValidationBundle\Form\Util\FormHelper; | ||
|
||
/** | ||
* @author Warnar Boekkooi <[email protected]> | ||
*/ | ||
class FieldDependency implements RuleCondition | ||
{ | ||
const FIELD_VALID = '='; | ||
const FIELD_INVALID = '!'; | ||
|
||
/** | ||
* Dependent field | ||
* @var string | ||
*/ | ||
public $field; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $condition; | ||
|
||
public function __construct($field, $condition = self::FIELD_VALID) | ||
{ | ||
$this->field = FormHelper::getFormName($field); | ||
$this->condition = $condition; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function macro() | ||
{ | ||
return 'field_dependency'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace Boekkooi\Bundle\JqueryValidationBundle\Form; | ||
|
||
/** | ||
* @author Warnar Boekkooi <[email protected]> | ||
*/ | ||
interface RuleCondition | ||
{ | ||
/** | ||
* Get the twig macro name to call. | ||
* @return string | ||
*/ | ||
public function macro(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% macro field_dependency(condition, rule) %} | ||
{%- set isRequired = rule.name is sameas('required') -%} | ||
|
||
{%- if isRequired -%} | ||
var dep = form.find("[name=\"{{ condition.field|e('js') }}\"]")[0]; | ||
{%- endif -%} | ||
|
||
if ( | ||
{%- if condition.condition is sameas('!') -%}!{%- endif -%} | ||
( | ||
{%- if isRequired -%} | ||
!$.validator.methods.required.call(validator, validator.elementValue(dep), dep, true) || {% endif -%} | ||
"{{ condition.field|e('js') }}" in validator.errorMap || "{{ condition.field|e('js') }}" in validator.invalid)) { | ||
return false; | ||
} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.