Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi,

    One way would be to add a javascript or jQuery function to the textfield that limits the number of characters a user can type in. That would need to be done with some custom coding, as it’s not something that’s built-in.

    Thread Starter imemine

    (@imemine)

    Ok.

    I can do it with javascript when I am not using “WordPress editor ” just by adding a maxlength attrib to it like
    $('textarea[name=content]').attr('maxlength','6');
    but when using “WordPress editor ” tinyMce I am unable to even select the iframe.

    I managed to select the Text tab out of the ‘Text’ and ‘Visual’ tab using the same command as above but the button in the editors toolbar doesn’t respect the maxlength and will put code in the editor, but still I can’t select the iframe.

    Plugin Support angelo_nwl

    (@angelo_nwl)

    Thread Starter imemine

    (@imemine)

    Doesn’t work for me.

    tinyMCE.activeEditor.onKeyUp.add( function() {
    
    				// Strip HTML tags, WordPress shortcodes and white space
    
    				editor_content = this.getContent().replace(/(<[a-zA-Z\/][^<>]*>|\[([^\]]+)\])|(\s+)/ig,'');
    
    			console.log("found	"+editor_content.length );
    
    			//The line above give the correct length
    
    if ( editor_content.length > 5 ) {
    			console.log("true	"+editor_content.length );
    
    			// these values are always 0 ,idk why .
    
    				} else {
    
    			console.log("false	"+editor_content.length );
    
    				}
    			}

    Plus the code doesn’t work when I copy paste data.

    One more question, how do I make this a required field ?

    You would probably be better off using a filter hook to do this rather than jQuery.

    To do so would require coding though so if you’re not comfortable with that you’ll need to seek the assistance of a developer.

    Thanks,
    Phil

    You would probably be better off using a filter hook to do this rather than jQuery.

    To do so would require coding though so if you’re not comfortable with that you’ll need to seek the assistance of a developer.

    Thanks,
    Phil

    Thread Starter imemine

    (@imemine)

    I just want to get the work done ,php hook or jquery doesn’t matter to this project.

    I have accomplished what I wanted to accomplish .
    Here is what I did:

    Added this to style.css to disable the Visual button for the wordpress editor.

    div#page-left .hide-if-no-js.wp-switch-editor.switch-tmce {
        display: none!important;
    }

    Then to make sure that the html/text button is activated by default added this
    add_filter( 'wp_default_editor', create_function('', 'return "html";') );

    Added this in the header to make sure that the event info field is required and has length 500

    $('textarea[name=content]').attr('maxlength','500');
    $('textarea[name=content]').attr('required','');

    Do you think I made a mistake anywhere ?

    Thanks for your help guys ??

    Plugin Author Marcus (aka @msykes)

    (@netweblogic)

    if it works then it should be fine ??

    Thread Starter imemine

    (@imemine)

    ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Limit the length of Event Information’ is closed to new replies.