PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Adding a 'Color Picker'

  1. I have been incorporating simple Gravity Forms into my websites for a few months now and am constantly amazed by the possibilities.

    I am currently building my most ambitious form yet for my own web design business and wish to include a color picker like iColorPicker or other similar tool. I have found other similar forum questions and tried to apply the techniques demonstrated by Kevin for incorporating CK Editor into forms, but cannot put it all together.

    I have downloaded the js for iColorPicker , uploaded it to my site and am calling it in the page header. I am also calling the jquery script from Google code.

    I understand that I need to replace the relevant input, but am not quite sure where it this needs to be place:

    <script type="text/javascript">
        iColorPicker.replace( 'input_4_11' );
    </script>

    Any tips to put me in the right direction would be greatly appreciated.

    Cheers,

    Keiran

    Posted 13 years ago on Monday November 8, 2010 | Permalink
  2. I would place in the same location you include the iColorPicker JS file. Something like the following:

    <script type="text/javascript" src='....../iColorPicker.js'>
    <script type="text/javascript">
    jQuery(document).ready(function(){ iColorPicker.replace( 'input_4_11' ) });
    </script>
    Posted 13 years ago on Monday November 8, 2010 | Permalink
  3. Hi Alex. Thanks for getting back to me so quickly. I do appreciate it.

    I have tried the suggested solution but when I add the iColorPicker replace script, the form disappears altogether.

    This is my test page of the form so far.

    I am probably missing something really obvious like a jquery conflict with my current theme (the Genesis framework).

    Posted 13 years ago on Monday November 8, 2010 | Permalink
  4. No luck yet with finding a solution to this little problem. I am possibly missing something very simple.

    As far as I understand, to use any color picker script within my form (like iColorPicker for example), I need to do the following steps: (please feel free to correct me!)

    1. Place a 'Single Line Text' field in the form.
    2. View page source and get the input id for this field.
    3. Call jquery and iColorPicker scripts in page header.
    4. Add script to replace input in text field to iColorPicker. I have tried the following scripts using the relevant input field id:

    <script type="text/javascript">
    jQuery(document).ready(function(){iColorPicker.replace( 'input_4_11' )});
    </script>

    or

    <script type="text/javascript">
        window.onload = function()
        {
            iColorPicker.replace( 'input_5_11' );
        };
    </script>

    and many other variations, but cannot get this little trick to work.

    Any suggestions on how to insert a color (or 'colour' as we spell here in Australia) picker to work would be greatly appreciated.

    Cheers :-)

    Posted 13 years ago on Monday November 8, 2010 | Permalink
  5. dreamwhisper
    Member

    Did you insert the iColorPicker.js in the header or footer under Genesis Theme options? It isn't showing in your header or footer, but rather in your content. Alternatively, you can do it in functions.php using http://codex.wordpress.org/Function_Reference/wp_enqueue_script. Also, it didn't appear to me that you added the class to your field.

    Their example uses a class of iColorPicker for the input, though I didn't really delve into the instructions.
    <input id="mycolor" name="mycolor" type="text" value="#ffcc00" class="iColorPicker" />

    Posted 13 years ago on Monday November 8, 2010 | Permalink
  6. There seems to be a couple of issues here.
    1- The iColorPicker seems to be conflicting with the conditional logic (that is the reason your form is blank/hidden sometimes
    2- This script does not support the initialization script you are trying to implement. It expects that your input is of a certain class (i.e. <input class='iColorPicker' /> ). The problem is that Gravity Forms won't allow you to add a custom class to the input. You can only add one to the parent

    What I would recommend is start with a form that does not have conditional logic in it, and get the color picker working there. Then add the conditional logic to your form.

    Good Luck!

    Posted 13 years ago on Monday November 8, 2010 | Permalink
  7. dreamwhisper
    Member

    This color picker was rather easy to implement: http://gusc.lv/jquery/gccolor.html

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
    	<link rel="stylesheet" type="text/css" href="../jquery.gccolor.1.0.3/css/gccolor.css" />
    	<script type="text/javascript" src="../jquery.gccolor.1.0.3/jquery.gccolor.1.0.3.js"></script>
    	<script type="text/javascript">
    		var $j = jQuery.noConflict();
    		var testChange = function(target, color){
    			target.val('#' + color);
    		}
    	  $j(document).ready(function(){
    	  	$j('#input_1_17, #input_1_18, #input_1_19, #input_1_20, #input_1_21').gccolor({
    				onChange : testChange
    			});
    		});
    	</script>
    Posted 13 years ago on Monday November 8, 2010 | Permalink
  8. Thanks Alex and Dreamwhisper, for your helpful suggestions and comments. I will revisit the idea when time permits but for now, I have retained the conditional logic elements of the form (more important than the colour picker) and embedded a colour picker outside the form (in the sidebar) for clients to use if they need to reference a HTML colour code.

    Many thanks for your wonderful assistance though :-)

    Posted 13 years ago on Saturday November 13, 2010 | Permalink
  9. not working :( with this script

    http://desertseadesign.com/qr-card-order-form/

    <script type="text/javascript">
    		var $j = jQuery.noConflict();
    		var testChange = function(target, color){
    			target.val('#' + color);
    		}
    	  $j(document).ready(function(){
    	  	$j('#input_9_33').gccolor({
    				onChange : testChange
    			});
    		});
    	</script>

    not sure if the javascript is right

    Posted 13 years ago on Tuesday February 8, 2011 | Permalink
  10. Seems to me that your scripts are out of order. You have included the color picker script BEFORE including jquery, and it's throwing errors. It is affecting other scripts on the page too (maybe less important or unneeded things):

    Error: jQuery is not defined
    Source File: http://desertseadesign.com/js/gf_likert.js
    Line: 4
    
    Error: jQuery is not defined
    Source File: https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js
    Line: 17
    
    Error: jQuery is not defined
    Source File: http://desertseadesign.com/jquery.gccolor.1.0.3/jquery.gccolor.1.0.3.js
    Line: 368
    
    Error: jQuery is not defined
    Source File: http://desertseadesign.com/qr-card-order-form/
    Line: 12

    jQuery should be included before all your other scripts that rely on jQuery. Try moving the color picker script (external and inline) to just before the closing </head> and see if it starts working.

    Posted 13 years ago on Wednesday February 9, 2011 | Permalink
  11. There is also a lot of JavaScript on that page. It may need more than a simple move to after jQuery is included to make it work, but my previous suggestion still stands.

    Screenshot of the script listing:
    http://i.min.us/iekgWO.png

    Posted 13 years ago on Wednesday February 9, 2011 | Permalink
  12. thanks. I will try this tonight

    Posted 13 years ago on Thursday February 10, 2011 | Permalink
  13. it works now. Thank you so much

    Posted 13 years ago on Thursday February 10, 2011 | Permalink
  14. Glad you got that sorted.

    Last night I checked the size of that page and the download time out of curiosity, and it's huge. Once you're done building the site, you may want to consider optimizing it to use less resources.

    Check this PDF:
    http://k.min.us/iesw0K.pdf

    1.2 MB for the page and 208 HTTP requests.

    But I'm still glad you got your color picker working.

    Posted 13 years ago on Thursday February 10, 2011 | Permalink

This topic has been resolved and has been closed to new replies.