[WIP] Selectbox auto default value#183
Open
h4kuna wants to merge 5 commits intonette:masterfrom
h4kuna:selectbox-auto-default-value
Open
[WIP] Selectbox auto default value#183h4kuna wants to merge 5 commits intonette:masterfrom h4kuna:selectbox-auto-default-value
h4kuna wants to merge 5 commits intonette:masterfrom
h4kuna:selectbox-auto-default-value
Conversation
Member
|
That's fine, I tried something like this. But beware of that |
Contributor
Author
|
I thinking about one property for value sorted by priority like this: class NoValue {
// probably it can be singleton :)
}BaseControl protected $value = [
'value' => new NoValue,
'default' => new NoValue,
'prompt' => new NoValue,
'auto' => new NoValue, // defined by input
];
public function setPrompt($value)
{
$this->value['prompt'] = $value;
}
protected function setValue($value)
{
...
}
public function setDefaultValue($value)
{
...
}
public function getValue()
{
foreach ($this->value as $value) {
if (!$value instanceof NoValue) {
return $value;
}
}
return null;
}This implementation is not for this PR. |
f3l1x
reviewed
Jun 13, 2018
src/Forms/Controls/SelectBox.php
Outdated
| private $prompt = false; | ||
|
|
||
| /** @var bool */ | ||
| private $lockAutoDefault = false; |
Member
There was a problem hiding this comment.
LockAutoDefault looks weird to me.
Contributor
Author
|
It is little bit complicated, in render time. Macro inputif i use {input foo size => 2}It is compiled echo end($this->global->formsStack)["foo"]->getControl()->addAttributes(['size' => 2]);I haven't access to the instance Selectbox. This i can resolve like: echo end($this->global->formsStack)["foo"]->addAttributes(['size' => 2]);Html select n: macro<select n:name="foo" size="2"></select>Know i value of attribute size in compile time? <select size="2"<?php
$_input = end($this->global->formsStack)["foo"];
echo $_input->getControlPart()->addAttributes(array (
'size' => NULL,
))->attributes() ?>><?php echo $_input->getControl()->getHtml() ?></select> |
Contributor
Author
|
I don't know how continue this PR. Must macros works from template when set up size? If yes, i need help with n:macro and compile time. @dg wrote anything same, could you paste your resolution or idea? |
2df07d6 to
82e9980
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
If you create form with selectbox and render it. Nothing change and submit form, we get first value of items. This unite behavior if you create selectbox and call method getValue() then return first item. It does not matter the order of the called methods. You can see comit named "test".
Example
Old bahavior
Value
nullis out of range.New behavior
What do you think?