-
-
Notifications
You must be signed in to change notification settings - Fork 436
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
Added frontend_type color #2945
Conversation
Oh nice one 👍. Tested and it works just fine. Only thing to note. In @luigifab's PR, he has the option of Here's the results in the database:
But overall, I think this is a good addition, so I approve. |
I didn’t find anything in the specification about having the hash or not 😞 |
I ran this SQL, to update the value from update core_config_data set value='ff0000' where path LIKE "%colortest"; Then when I reloaded the config page, the color picker was black instead of red. So maybe, we can add this method to Color.php: /**
* @param string|null $index
* @return string
*/
public function getEscapedValue($index = null)
{
$value = parent::getEscapedValue($index);
return '#' . ltrim($value, '#');
} This would allow someone to use the color picker element on a value that doesn't have the hash in the database. Of course the new value would end up with the hash, so I don't know if that's going to mess up their code then. But, this is a new feature so it's not breaking anybody's code automatically. Edit: Fixed the above code to call |
In HTML5 you just choose the color and the magic happens in the background. In jscolor you can both choose the color and enter it in a box. this makes the difference between the two. Adding a hash before the string makes it a hexadecimal value. More details here https://jscolor.com/docs/#api--opts--hash. This PR is a great feature and I support it. |
In this case your proposal to check if a hexadecimal string is preceded by a hash appears to be logical. Maybe it should be updated in the database as well, but that would complicate things to be achieved. |
In jscolor hash option is set to false by default color : function(target, prop) {
this.required = true; // refuse empty values?
this.adjust = true; // adjust value to uniform notation?
this.hash = false; // prefix color with # symbol? |
great idea but has a problem, if my value is saved (initially) without the hash, I probably expect it to keep being saved without the hash... I'll try to work something out |
Yes, agreed it would be better to allow hash=true or hash=false. I suppose there's a way to do this with two inputs (one color and one text). I will see what you come up with. |
I've committed a version that manages the
it's done with an hidden input and a small bit of javascript. maybe not the super best way but at least I didn't have to add a backend model or anything more complicated. what do you think? |
That's pretty neat! One problem I encountered. Set |
This fixes it: $html = '<input id="' . $id . '" type="text" name="' . $this->getName()
. '" value="' . ($with_hash ? '#' : '') . $valueWithoutHash . '" ' . '/>' . "\n"; |
@justinbeaty great!!! |
I added the XML code in a system.xml file and got the color field in the Backend. Initially the color selector is set to RGB mode, but the user can switch to HEX. The hex value is predicated by #. I went through several scenarios
Seeing this behavior I deleted the # in front of the value and I did not save. When I used again the color picker, the value had # in front of it, which was not added by this PR. This came from browser. This behavior is found in all Chromium-based browsers (Chrome, Edge, ...). In the case of Firefox, the color selector is totally different, it does not have the HEX option. Chromium-based Firefox |
Do you confirm this phpMyAdmin or mysql cli client? In Chrome, the hex value will always have the hash in the color picker. |
Also I have an idea for possible improvement, I'll test now. |
I think we should add that models. 😛 Would |
the picker is only a way to input a color, I think "color" is correct, it's also the name used by html5
why tho? |
I've committed @justinbeaty's code for managing color also in products' attributes |
I agree
I also think
The script can be extended, but let's make a discussion about it.
Thanks, although I was okay with making a separate PR. I should do a bit more testing to see how this attribute shows up in collections, etc. I don't foresee anything negative. |
@fballiano Let's revert |
…utes" This reverts commit 1fd0e08.
done |
what are we doing with this PR? trash it? |
IIRC, it was ready to merge, just needed another approval. |
Will test right away |
yeah! |
--------- Co-authored-by: Justin Beaty <51970393+justinbeaty@users.noreply.github.com> Co-authored-by: Sven Reichel <github-sr@hotmail.com>
merged and cherrypicked to 20.0 |
In #2937 it came the idea of having support for input type color for adminhtml forms, this PR adds it.
To test it, in a system.xml file, add some rows like these ones:
then check the "system -> configuration" so see that it works, eg:
Related Pull Requests