0

I am creating a popup which shows some product details along with dynamic contact list.how to make this dynamic picklist as required or through an error when if its not selected or the value is "--select--" when clicking on button? my code is in imageenter image description here

1
  • please use edit to indicate current state of code - don't paste pictures, see How to Ask for formatting tips
    – cropredy
    Jan 2 '19 at 19:57
0

As mentioned by you in the question, there will be always a default value in selectList i.e. "--select--" will be always selected, hence make below changes to your code

  1. In addition to checking null or blank value, also check if the value is not equal to "--select--" in your controller and throw the error back.
  2. Remove required = true from selectList as there will be always a default value of "--select--" in your selectList.
0

In apex controller side. You can write custom messages .

Assume, suppose you are validating picklist part while submitting the record

if(string.isBlank(selectedConId)){
  ApexPages.addmessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select 
a value'));
     return null;
}

Use following tag in vf page:

    < apex:Pagemessages/>       
5
  • ,Thanks for reply. I tried with this and it showed error void(isblank) stirng type doesn't exist. i added string.isblank() but still its executing when clicking on button and showing error in debug log.
    – chandu
    Dec 26 '18 at 8:57
  • Just check seleccondid==null || seleccondid==''.. it may work Dec 26 '18 at 11:36
  • 1
    1) String.isBlank(selectedConId) is preferred construction and 2) need to remove required= on selectList - otherwise controller will never be invoked
    – cropredy
    Dec 27 '18 at 1:19
  • @cropredy still it's not working.
    – chandu
    Jan 2 '19 at 11:52
  • @annappa PH Stiil facing same issue
    – chandu
    Jan 2 '19 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.