Skip Navigation

[Résolu] Colorpicker Preview

This support ticket is created Il y a 6 années et 8 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Ce sujet contient 1 réponse, a 2 voix.

Dernière mise à jour par Nigel Il y a 6 années et 7 mois.

Assisté par: Nigel.

Auteur
Publications
#683311

Hi,

I created a color-preview div which I am showing after the color picker text field.
I would like to use jquery to change the background of that div live as soon as a new picker value is selected on the iris-picker.

Problem is, the iris picker does not actually send the hex value anywhere. How could I intercept the color that is populated within the field before the form is submitted.

Thank you

Adrian

#685287

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Hi Adrian

I took a look at the source code in Types for where colorpicker is invoked, and I based upon that I came up with the following which will update the background-color CSS property of a DIV with a class of "colour-swatch".

(function($) {
    $(document).ready(function() {

        $(document).click(function(e) {
            if ( !$(e.target).is("input.js-wpt-colorpicker, .iris-picker, .iris-picker-inner") &&
                $('input.js-wpt-colorpicker.js-wpt-colorpicker-inited').length > 0 )
            {
                var colour = $('input.js-wpt-colorpicker').val();
                $('.colour-swatch').css( 'background-color', colour );
            }
        });
    });
})(jQuery);

Edit that class name as required then trying adding the code to the custom JS box on your CRED form.