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 bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public:
       
      Download & Docs: https://gitlab.com/baumrock/RockPdf
       
      You can combine it easily with RockReplacer: 
       
    • By Soma
      LogMaintenance
      A simple ProcessWire module to give some maintenance control over log files. I found myself often having lots of log files for different things that can grow more or less quickly to a size where they can be difficult to maintain. The built in Logger of PW does a good job of giving you the possibility to delete or prune logs. But it has to be done manually and sometimes a log grows into millions of lines, which makes it often impossible to even prune it as it's too large.
      LogMaintenance uses LazyCron to run the maintenance task and there's several settings you can setup on a global or per log basis.
      Archive: will create zip files for each log file in logs/archive/ folder and add the log each time the maintenance is run to a subfolder containing the datetime.
      Lines: keeps logs to a certain number of lines 
      Days: keeps the log to a certain number of days
      Bytes: keeps the log to a certain amount of bytes
      Each setting is checked from top down, the first setting to contain something is used. So if you check the "Archive" option, all other settings are ignored and logs are archived everytime the LazyCron is executed. If you want to keep your logs to a certain amount of bytes just leave all other settings to 0 or blank.
      Per Log Settings
      There's a textarea that you can use to setup a config for a specific log file one per line. All the logs you define here ignore the global settings above. The syntax for the settings is:
      logname:[archive]:[lines]:[days]:[bytes] 
      errors:1:0:0:0 // would archive the errors log messages:0:10000:0:0 // will prune the errors log to 10000 lines  
      The module can be found on github for you to check out. It's still fresh and I'm currently testing.
      https://github.com/somatonic/LogMaintenance
    • By teppo
      Fieldtype Page IDs is a third party Fieldtype that, simply put, stores Page references as integers (Page IDs).
      This fieldtype was built as a quick and dirty workaround for Page Reference fields' inability handle self-references due to circular reference issues. A project I've been working on for a while now includes a combination of RepeaterMatrix content blocks and tagging/categorization system that would've resulted in a lot of duplicate pages (and plenty of unnecessary manual work for content editors) had I used built-in Page Reference fields, and thus a new Fieldtype felt like the most sensible approach.
      Fieldtype Page IDs was designed to be loosely compatible with Page References in order to make conversions between the two feasible, but it is quite limited feature wise:
      largely due to the fact that stored values are actually just integers with no connection to Pages whatsoever some advanced selectors and related features are not supported, and page values can't be directly accessed configuration settings are limited to the bare essentials (selector string and Inputfield class) only a handful of Inputfields (AsmSelect, Checkboxes, Text) are (currently) supported Anyway, in case you need to store Page IDs (and Page IDs only) and are happy with the limitations mentioned above, feel free to give this Fieldtype a try. It has been working fine for me in one particular project, but hasn't been tested that much, so please tread carefully – and let me know if you run into any issues.
      GitHub repository: https://github.com/teppokoivula/FieldtypePageIDs
      Modules directory: https://modules.processwire.com/modules/fieldtype-page-ids/
    • By daniels
      This is a lightweight alternative to other newsletter & newsletter-subscription modules.
      You can find the Module in the Modules directory and on Github
      It can subscribe, update, unsubscribe & delete a user in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.
      This module fits your needs if you...
      ...use Mailchimp as your newsletter / email-automation tool ...want to let users subscribe to your newsletter on your website ...want to use your own form, validation and messages (with or without the wire forms) ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms) ...like to subscribe, update, unsubscribe or delete users to/from different lists ...like the Mailchimp UI for creating / sending / reviewing email campaigns *I have only tested it with PHP 7.x so far, so use on owners risk
      EDIT:
      I've updated the module to 0.0.4. I removed the instructions from this forum, so I don't have to maintain it on multiple places. Just checkout the readme on github 🙂
      If you have questions or like to contribute, just post a reply or create an issue or pr on github. 
    • By bernhard
      WHY?
      This module was built to fill the gap between simple $pages->find() operations and complex SQL queries.
      The problem with $pages->find() is that it loads all pages into memory and that can be a problem when querying multiple thousands of pages. Even $pages->findMany() loads all pages into memory and therefore is a lot slower than regular SQL.
      The problem with SQL on the other hand is, that the queries are quite complex to build. All fields are separate tables, some repeatable fields use multiple rows for their content that belong to only one single page, you always need to check for the page status (which is not necessary on regular find() operations and therefore nobody is used to that).
      In short: It is far too much work to efficiently and easily get an array of data based on PW pages and fields and I need that a lot for my RockGrid module to build all kinds of tabular data.

      Basic Usage

       
      Docs & Download
      https://modules.processwire.com/modules/rock-finder/
      https://gitlab.com/baumrock/RockFinder/tree/master
       
      Changelog
      180528, v1.0.4 add custom select statement option 180516 change sql query method, bump version to 1.0.0 180515 multilang bugfix 180513 beta release <180513 preview/discussion took place here: https://processwire.com/talk/topic/18983-rocksqlfinder-highly-efficient-and-flexible-sql-finder-module/