-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes implementation of form's and element's getValue() and clear() methods #13500
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d885ad7
Changes to Form::getValue() method
crnjakovic e508b13
Changes implementation of Form::clear()
crnjakovic f19b878
Fixed wrong variable name causing CI to fail
crnjakovic 6d92138
Fixed variable names causing CI to fail
crnjakovic 3cd088c
Changes to Element::getValue() and Element::Clear()
crnjakovic a74314e
Update CHANGELOG-4.0.md
crnjakovic 8fc3352
Fixes Element::getValue
crnjakovic 69d1a5c
Changed is_null() to === null
crnjakovic ebde401
Update CHANGELOG-4.0.md
crnjakovic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
namespace Phalcon\Forms; | ||
|
||
use Phalcon\Tag; | ||
use Phalcon\Validation; | ||
use Phalcon\ValidationInterface; | ||
use Phalcon\DiInterface; | ||
|
@@ -552,7 +553,7 @@ class Form extends Injectable implements \Countable, \Iterator | |
*/ | ||
public function getValue(string! name) -> var | null | ||
{ | ||
var entity, method, value, data, $internal, forbidden; | ||
var entity, method, value, data, $internal, forbidden, element; | ||
|
||
let entity = this->_entity; | ||
let data = this->_data; | ||
|
@@ -622,6 +623,20 @@ class Form extends Injectable implements \Countable, \Iterator | |
if method_exists(this, method) { | ||
return this->{method}(); | ||
} | ||
|
||
/** | ||
* Check if the tag has a default value | ||
*/ | ||
if Tag::hasValue(name) { | ||
return Tag::getValue(name); | ||
} | ||
|
||
/** | ||
* Check if element has default value | ||
*/ | ||
if fetch element, this->_elements[name] { | ||
return element->getDefault(); | ||
} | ||
|
||
return null; | ||
} | ||
|
@@ -661,7 +676,7 @@ class Form extends Injectable implements \Countable, \Iterator | |
/** | ||
* Clears every element in the form to its default value | ||
* | ||
* @param array fields | ||
* @param array|string|null fields | ||
*/ | ||
public function clear(var fields = null) -> <Form> | ||
{ | ||
|
@@ -687,17 +702,30 @@ class Form extends Injectable implements \Countable, \Iterator | |
let this->_data = data, | ||
elements = this->_elements; | ||
|
||
if typeof elements == "array" { | ||
for element in elements { | ||
if typeof fields != "array" { | ||
element->clear(); | ||
} else { | ||
if in_array(element->getName(), fields) { | ||
element->clear(); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* If fields is string, clear just that field. | ||
* If it's array, clear only fields in array. | ||
* If null, clear all | ||
*/ | ||
if typeof elements == "array" { | ||
if is_null(fields) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
for element in elements { | ||
Tag::setDefault(element->getName(), element->getDefault()); | ||
} | ||
} else { | ||
if typeof fields == "array" { | ||
for element in elements { | ||
if in_array(element->getName(), fields) { | ||
Tag::setDefault(element->getName(), element->getDefault()); | ||
} | ||
} | ||
} else { | ||
if fetch element, elements[fields] { | ||
Tag::setDefault(element->getName(), element->getDefault()); | ||
} | ||
} | ||
} | ||
} | ||
return this; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add it at the end of section instead of beginning