Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8628789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:38:19+00:00 2026-06-12T08:38:19+00:00

I need to disable button in case the text input value length is less

  • 0

I need to disable button in case the text input value length is less than 3.

I was trying to use js but the button is not disabled its just changing is color

 <p:autoComplete id="ac"
                    value="#{bean.selectedNetCode}" 
                    completeMethod="#{bean.complete}"
                    maxlength="3"
                    size="3"
                    maxResults="10"
                    onkeyup="checkLength(this.value)">
        <p:ajax event="itemSelect" update="genButton" listener="#{bean.handleNetCodeChange}"/>
    </p:autoComplete> 



 function checkLength(value){
      if(value.length <= 2){
      document.getElementById("genButton").disabled = true;
 }

Any idea why ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:38:21+00:00Added an answer on June 12, 2026 at 8:38 am

    You can define the attribute widgetVar of p:commandButton, and that will give you access to the component via javascript.

    Then, you have some methods at your disposal. From PrimeFaces 3.4 Documentation:

    • disable(): Disables button
    • enable(): Enables button

    Example:

    <p:autoComplete onkeyup="checkLength(this.value)">/>
    <p:commandButton widgetVar="myButton" />
    
    function checkLength(value){
         if(value.length <= 2)
             myButton.disable();
    }
    

    UPDATE 07/2021:

    As pointed by dian jin in the comments, when using PimeFaces 4.0 to 5.0 you will need to call PF('myButton').disable(); to reference widgetVar properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to disable/not show a Change Install Location button in installer. How do
OK, I have two HTML select elements and a button. I need to disable
I need to make disable or inactive the home button of my android phone
I have a Button on appwidget, that I need to 'enable'/'disable' programmatically from a
For example I need to disable two buttons in runtime. After I disabled first
I've got a button that I need to be disabled when validation errors occur
I need the button submit to be disabled unless JavaScript is on. I tried:
I need to disable delete button GLOBALLY based on some condition? The following solutions
I need to disable a button based on one parameter present month . Here
Ha-ii ,am doing an in-app purchase in my application,i need to disable a button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.