• Hi there,
    Love the functionality so far, but could you add an “onclick” action to the text field tag generation? I’m looking to add something like onclick=”javascript:value=”;” to the text fields so that the starting values disappear when clicked on.

    Thanks,
    Megan

Viewing 11 replies - 1 through 11 (of 11 total)
  • I second this! I would love that functionality! Also have a text color change. The pre-focus text a light grey, then on focus the typed text is dark grey or black.

    To get WAI-AAA validation, you have to include a default value in the inputs. You can do this now. But when you click on the input box, you have to delete the default value before writing anything. Some code will clear the value of the inputs boxes when you click them:

    <input type=”text” id=”author” name=”author” value=”Author” onfocus=”if (this.value == ‘Author’) {this.value = ”;}” onblur=”if (this.value == ”) {this.value = ‘Author’;}” />

    It is like the search input on this page, on top rigth corner (Search WorPress.org). I second this too, with the pre-focus color on light grey.

    I am going to try adding this into line 216 of includes/classes.php (version 1.10.1)

    $atts .= ' onfocus="if (this.value == \'' . esc_attr( $value ) . '\') {this.value = \'\';}" onblur="if (this.value == \'\') {this.value = \'' . esc_attr( $value ) . '\';}"';

    This is tested and working.
    Cheers!

    I believe the same line I just posted could be added to line 70 of modules/text.php in the new 2.0 version, but I’m not sure about the block of code above it. So I’d suggest using

    if ( $value != '' ) {
    	$atts .= ' onfocus="if (this.value == \'' . esc_attr( $value ) . '\') {this.value = \'\';}" onblur="if (this.value == \'\') {this.value = \'' . esc_attr( $value ) . '\';}"';
    }

    tomcat23 you’re awesome! thanks so much!

    I’m trying it below line 75 in the 2.0.7 version…

    Oh,it works. basically, me slug of code just adds to the html before it gets all rendered properly. Pretty simple. Just add my if statement before the line that reads
    $html = '<input type="text" name="' . $name . '" value="' . esc_attr( $value ) . '"' . $atts . ' />';

    Oh, and thanks!

    Thank You, tomcat23 !
    I’ve searched everywhere for this. It works great for me in the 2.1 version. Thank you..thank you.

    Maybe you can just add that behaviour by an unobstructive JavaScript call which won’t require any changes in plugin core. Should be easy to setup with jQuery.

    amazing! so glad I found this. Thanks Tomcat!

    nilsnh

    (@nilsnh)

    Tomcat23, I salute you. ?? I was desperately trying to put Javascript into a stylesheet to create this effect because I wasn’t sure about how to edit the plugin’s Javascript. And I soon discovered that it isn’t possible to do it that way, but luckily I came over this thread.

    Thanks!

    Thank you!!
    Working in version 2.2, added the if statement to line 83.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Plugin: Contact Form 7] Feature Request – add onclick action’ is closed to new replies.