Jump to content

Fieldtype ColorPicker


Soma
 Share

Recommended Posts

Soma, I had a couple of questions...

How do you test for if it is set? Is this possible? isset doesn't appear to work, guess that's probably normal though...

Also, is it possible to unset it so that people can choose a colour but if they want to return to the default, they can remove all output from the field?

I'm using a default background pattern for my site but want to give the user an option to change the header colour. If they want to go back to the pattern, I'm not to sure how to do this without adding a checkbox where they have to tick "I want to use a bg color" and also provide a color.

Link to comment
Share on other sites

As you may noticed or not it has FFFFFF as default value. You could test for it. Im not really sure if having it this way makes sense for a color field or not.

Resetting the value to default isnt implemented simply bcause I havent had the need. Maybe a button or something to reset would be good.

Link to comment
Share on other sites

I have implemented a default value you can set in the field settings. Which means you can decide for yourself. i.e. "EAEAEA" or "". Which has effect on how you can test the field. Not sure how others have implemented the colorpicker, but this would be backward compatible if you set it to default "FFFFFF" as before.

And a link "reset" alongside every colorpicker. I'll have to test a little more, but it works fine but haven't had time to commit the changes.

Link to comment
Share on other sites

  • 1 month later...

Just because I am really nice and like to keep things nice and tidy for young Soma...

Is there an issue with using the color picker in conjunction with a repeater or a page select field? (or in my case, a mixture of both)

Happy Days!
 

Joss

Link to comment
Share on other sites

Hey Joss, thanks for the report! ;)

I just commited an update that may fix your issue, even though I don't know what it is. I haven't tried with repeater until now, and I couldn't even open the page as It throws a fatal error. In the last implementation of the default value feature it seems it was not compatible with repeaters.

** 1.0.4 **

- fixed bug with use in repeater

  • Like 1
Link to comment
Share on other sites

  • 6 months later...

The colorpicker has been updated to 1.0.7. with fixed and a new swatches feature.

- Since 1.0.6 the colorpicker supports color swatches to add predefined colors for easy selection. Thanks @Rayden for the implementation.

- It's now also possible to add a transparent default or swatch value with the string "transp".

- fixed a bug with numeric values like 333333, 555555 which caused the colorpicker to not init correctly.

A screen showing the swatches.

post-100-0-76063500-1376302472_thumb.png

Thanks for Raymond Geerts for the update and fixes.

  • Like 1
Link to comment
Share on other sites

Plugin needed the color as string not as int.  Was fixed with parseInt.

Update also prevent box collapse on the container.

I'm not to happy about the transp as name for transparent.

Thanks Martijin for you help also. It was fixed with value.toString() :)

The "transp" is ok and it was the easiest way to keep backward compatibility. It would require to reinstall the module to change the schema, though it could also be done with a update script check. I don't see why transp is a problem. And just because of transparent making the data field to 11 chars instead of 6 is not nice at the end.

But I'm not happy at all to add the prevent collapse issue, which is IMO a problem of the admin theme from the start. And since the default admin theme has no clearing on the widget content box, I'm fighting with this in various modules and custom admin pages and the admin theme. Resulting in the same fix in different modules and themes over and over again. Some solve it this way some the other way. It would be a easy fix in the core and I mentioned this so many times already that I gave up. This results in so many inconsistency now throughout the themes and modules, I hope with the new admin theme update in the future this will be fixed in some way. 

Link to comment
Share on other sites

It would be a easy fix in the core and I mentioned this so many times already that I gave up. This results in so many inconsistency now throughout the themes and modules, I hope with the new admin theme update in the future this will be fixed in some way. 

Totally agree with the point about the box collapse. (Ryan Help!, see Soma's post before this one "ui-widget-content")

I actually have no idea what you guys are talking about–tell me what to change? I understand code better than concept when it comes to CSS, so might need you to be literal as to what you suggest?

Link to comment
Share on other sites

.ui-widget-content needs to calculate it's height, the css overflow property can solve it.

Thanks, I have added this to the /wire/templates-admin/styles/inputfields.css

.Inputfields > .Inputfield > .ui-widget-content {
        /* the Inputfield's content, padded from the borders */
        padding: 1em;
        overflow: auto; 
}

...but am seeing odd results, specifically this scrollbar:

post-2-0-22858300-1376477096_thumb.png

So I changed it to this:

.Inputfields > .Inputfield > .ui-widget-content {
        /* the Inputfield's content, padded from the borders */
        padding: 1em;
        overflow-y: auto;
        overflow-x: hidden;
}

...and that seems to work. I'm not seeing any more oddities, but will keep testing. 

Just wanted to make sure this is consistent with what you guys are suggesting?

Also, it was mentioned earlier that there were various CSS hacks already in place to solve the problem that this CSS fixes? I guess I'm not sure what or where those are, but if you can point them out, it might help me to better understand the issue. Not to mention, if there is redundant/unnecessary code somewhere, I'd like to remove it. 

 
Link to comment
Share on other sites

Think your new styles will do, but there are more options.

Maybe the clearfix way is more robust, when I think about it.

You can do it with the clearfix way from Nicolas Gallagher.

.Inputfields > .Inputfield > .ui-widget-content {
    /* the Inputfield's content, padded from the borders */
    padding: 1em;
}

/* clearfix way, ps, don't need the IE7 zoom as PW doesn't allow IE7 in admin */
.Inputfields > .Inputfield > .ui-widget-content:before,
.Inputfields > .Inputfield > .ui-widget-content:after {
    content:"";
    display:table;
}
.Inputfields > .Inputfield > .ui-widget-content:after {
    clear:both;
}
  • Like 2
Link to comment
Share on other sites

  • 2 months later...

With the new admin templates that come with the 2.3.5 version of PW there seems to be a bug related to the color swatches.

When clicked they do not execute anymore, so the color value of the swatch is not send to the color value. I'm almost certain it is related to CSS.

Removing the "templates-admin" folder from the site folder gives the "old" admin template in which it works fine.

I had no luck yet looking for a fix. Has anybody an idea what change causes this problem, or how to fix it?

Link to comment
Share on other sites

Adrian, thanks for posting the links to that topic.

But taking a look at the code i see its not realy a solution. I think it will not work when having multiple color pickers in one template.

The thing is that the colorpicket swatch work fine in the default admin template. But stop working in the new admin template.

I have taken a closer look and see that the solution Pete has posted is working great

http://processwire.com/talk/topic/4650-new-processwire-admin-theme-on-dev-branch/?p=46380

I have modified the javascript from the colorpicker module and it works now great on the "old" and "new" template aswell. And made a pull request on GitHub for soma.

Thanks guys!

Edited by Raymond Geerts
  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Got ColorPicker installed. Works nicely. Thanks!

Just found a small issue when validating the admin page: "No p element in scope but a p end tag seen." I fixed it by moving the <p> tag in InputfiedColorPicker.module from line 51 to line 56 like so:

from:

		$out  = "\n<p><div id='ColorPicker_$this->name' style='border:2px solid #444; display:block;";
		$out .= "width:40px; height:40px; background-color:";
		$out .= $this->value == "transp"
				? $this->value . "; background-image:url({$this->config->urls->InputfieldColorPicker}transparent.gif);"
				: "#" . $this->value . "; background-image:none";
		$out .= "' data-color='" . $this->value . "'></div>";

to:

		$out  = "\n<div id='ColorPicker_$this->name' style='border:2px solid #444; display:block;";
		$out .= "width:40px; height:40px; background-color:";
		$out .= $this->value == "transp"
				? $this->value . "; background-image:url({$this->config->urls->InputfieldColorPicker}transparent.gif);"
				: "#" . $this->value . "; background-image:none";
		$out .= "' data-color='" . $this->value . "'></div><p>";

My admin theme is modified a little, but I think the error came from this. Anyway, very useful module!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...