Soma

Fieldtype ColorPicker

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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Thanks Soma, not sure whether it would be useful to others to have a reset or not but it may be. Is a colorpicker field essentially always set?

For now, using a checkbox alongside it works fine

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Okay, I will try later!

I am creating a sort of "metro" demo, so lots of flat colours and no gradients!

Actually, that would be an interesting addon - create a limited pallet of colours to pick from.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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.

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

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

And oops, you you're right about toString my mind's a floating int string... 

  • Like 1

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

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

post-577-0-78815700-1376404487_thumb.pngpost-577-0-74786800-1376404489_thumb.png

Welcome Pauline !

Edited by Martijn Geerts
  • Like 2

Share this post


Link to post
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. 

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks, that looks better–I will give this one a try. 

  • Like 1

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

I'm not sure what version you got, but the p tag wasn't missing closing tag, but it was wrong and not needed. Thanks for mention.

I pushed a little update with other small fixes.

  • Like 1

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Rudy
      Hi,
      I am writing a custom module that requires storing array of settings in the module config/settings.
      Is there a built-in fieldtype that allows me to store settings in an array (sort of like Repeater)?
      I tried using InputfieldAceExtended and InputfieldTextarea to store JSON array. Both times, my data was stored in the module settings (in the database) but upon reload, that information was not retrieved.
      Thanks
      Rudy
       
    • By Anssi
      A simple module to enable easy navigation between the public and the admin side of the site. After installation a green bar will appear to the upper side of the screen, containing a few navigation elements and displaying the PW version number.
      Heavily inspired by @apeisa's great AdminBar (Thanks!). I needed a bit simpler tool for my projects and as a result, this was made. Available on GitHub .

    • By Sebi
      I've created a small module which lets you define a timestamp after which a page should be accessible. In addition you can define a timestamp when the release should end and the page should not be accessable any more.
      Github: https://github.com/Sebiworld/PageAccessReleasetime
      Usage
      PageAccessReleasetime can be installed like every other module in ProcessWire. Check the following guide for detailed information: How-To Install or Uninstall Modules
      After that, you will find checkboxes for activating the releasetime-fields at the settings-tab of each page. You don't need to add the fields to your templates manually.
      Check e.g. the checkbox "Activate Releasetime from?" and fill in a date in the future. The page will not be accessable for your users until the given date is reached.
      If you have $config->pagefileSecure = true, the module will protect files of unreleased pages as well.
      How it works
      This module hooks into Page::viewable to prevent users to access unreleased pages:
      public function hookPageViewable($event) { $page = $event->object; $viewable = $event->return; if($viewable){ // If the page would be viewable, additionally check Releasetime and User-Permission $viewable = $this->canUserSee($page); } $event->return = $viewable; } To prevent access to the files of unreleased pages, we hook into Page::isPublic and ProcessPageView::sendFile.
      public function hookPageIsPublic($e) { $page = $e->object; if($e->return && $this->isReleaseTimeSet($page)) { $e->return = false; } } The site/assets/files/ directory of pages, which isPublic() returns false, will get a '-' as prefix. This indicates ProcessWire (with activated $config->pagefileSecure) to check the file's permissions via PHP before delivering it to the client.
      The check wether a not-public file should be accessable happens in ProcessPageView::sendFile. We throw an 404 Exception if the current user must not see the file.
      public function hookProcessPageViewSendFile($e) { $page = $e->arguments[0]; if(!$this->canUserSee($page)) { throw new Wire404Exception('File not found'); } } Additionally we hook into ProcessPageEdit::buildForm to add the PageAccessReleasetime fields to each page and move them to the settings tab.
      Limitations
      In the current version, releasetime-protected pages will appear in wire('pages')->find() queries. If you want to display a list of pages, where pages could be releasetime-protected, you should double-check with $page->viewable() wether the page can be accessed. $page->viewable() returns false, if the page is not released yet.
      If you have an idea how unreleased pages can be filtered out of ProcessWire selector queries, feel free to write an issue, comment or make a pull request!
    • By David Karich
      Thanks to the great Pro module "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use this module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      With this proof of concept I have created a module which adds the feature to copy a repeater item to the clipboard so that you can paste this item to another page with the same repeater field. The module has been developed very rudimentarily so far. It is currently not possible to copy nested items. There is also no check of Min/Max. You can also only copy items that have the same field on different pages. And surely you can solve all this more elegantly with AJAX. But personally I lack the deeper understanding of the repeaters. Also missing on the Javascript side are event triggers for the repeaters, which would make it easier. Like e.g. RepeaterItemInitReady or similar.
      it would be great if @ryan would implement this functionality in the core of RepeaterMatrix. I think he has better ways to implement this. Or what do you think, Ryan?
      Everybody is welcome to work on this module and improve it, if it should not be integrated into the matrix core. Therefore I put it for testing and as download on GitHub: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDublicate
      You can best see the functionality in the screencast: 
       
    • By anderson
      Hi,
      Please take a look at this:
      https://templatemag.com/demo/Good/
      The upper nav bar, including dropdowns like "pages" and "portfolios", what do you call this whole thing? At first I guess it's called "dropdown nav bar", but seems not.
      AND of course, what's the simplest way/module to achieve this in PW?
      Thanks in advance.