cancel
Showing results for 
Search instead for 
Did you mean: 

Mandatory dropdown in red colour

Former Member
0 Kudos

Hi all, I need to put a dropdown in a red marked colour if the user don't select anything on it.

I have try these method:

a) wd_this->message_manager->report_attribute_error_message(

message_text = text

element = wd_context_element

attribute_name = attribute ).

b) lo_view_controller = wd_this->wd_get_api( ).

cl_wd_dynamic_tool=>check_mandatory_attr_on_view(

EXPORTING

view_controller = lo_view_controller

IMPORTING

messages = msg_tab ).

But the dropdown in red is never been marked.

Am I forgetting something please?

Help please.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

If you want to make particular field as mandatory, u can maintain the WebDynpro Field properties as required.

when u insert element in UI(ROOTUIELEMENTCONTAINER), in the properties u find state has two options 1.required 2.normal Item.

Put it as required.

U automatically get * symbol beside that element.

U dont have to write any code.

Provide Reward Points.:-)

Answers (5)

Answers (5)

uday_gubbala2
Active Contributor
0 Kudos

Just thought to update that I am using a DropDownByIndex for this coding:

Suppose I have a context node by name NODE_IDX & have 2 attributes under this KEY & VALUE. I have associated a supply function POPULATE_NODE with my context node to fill it with values as how shown below:

METHOD populate_node .
* data declaration
  DATA lt_node_idx TYPE wd_this->elements_node_idx.
  DATA ls_node_idx LIKE LINE OF lt_node_idx.
  DATA lv_str TYPE string.

*** If I ommit writing 3 lines below then the system will by default have the 1st value of my
*** dropdown as selected & so would assume that the user has already selected 1 value
*** Try running the component with and without these 3 lines & check the difference
 ls_node_idx-key = ''.
 ls_node_idx-value = ''.
 APPEND ls_node_idx TO lt_node_idx.
  
  DO 10 TIMES.
    lv_str = sy-index.
    CONCATENATE 'TEXT'
                lv_str INTO lv_str SEPARATED BY space.
    ls_node_idx-key = sy-index.
    ls_node_idx-value = lv_str.
    APPEND ls_node_idx TO lt_node_idx.
    CLEAR ls_node_idx.
  ENDDO.

* bind all the elements
  node->bind_table( new_items            =  lt_node_idx
                    set_initial_elements = abap_true ).
ENDMETHOD.

I have bound the "texts" property of my DropDown to the attribute "Value" & I have changed the "state" property to "Required".

I also put the below coding within my WDDOAFTERACTION method to trigger error messages for any mandatory fields which the user hasn't filled out.

METHOD wddoafteraction .
  DATA: lt_msg TYPE cl_wd_dynamic_tool=>t_check_result_message_tab,
        lo_view_controller TYPE REF TO if_wd_view_controller.
  DATA lo_message_manager    TYPE REF TO if_wd_message_manager.

  lo_view_controller ?= wd_this->wd_get_api( ).

  lo_message_manager = lo_view_controller->get_message_manager( ).

  lo_view_controller = wd_this->wd_get_api( ).

  cl_wd_dynamic_tool=>check_mandatory_attr_on_view(
    EXPORTING
      view_controller = lo_view_controller
      display_messages = abap_true
    IMPORTING
      messages = lt_msg ).
ENDMETHOD.

Regards,

Uday

Edited by: Uday Gubbala on Jun 9, 2009 11:39 AM

uday_gubbala2
Active Contributor
0 Kudos

Hi Jorge,

Have you actually taken care to fill your DropDown with an initial value? Because by default the system will have 1 value within your DropDown as selected due to the LeadSelection so it will assume that the user has already selected the first value within the DropDown as his choice if he does not make any input. Because of this the system wouldnt trigger any error message eventhough the user hasnt selected any entry.

Regards,

Uday

Former Member
0 Kudos

Please,help!

Former Member
0 Kudos

I am facing the same problem, ( but insted of dropdown I have input field )

Can any one pls give me hint, how to make a field mandatory and then mark it as well ? ( only changing the state to REQUIRED does not help enough ) ?

Regards,

Former Member
0 Kudos

Hi,

Changing the state to REQUIRED is only a hint to the user in the UI that its a mandatory attribute and you have to write code to check whether value is entered or not. For more information on these mandatory values, check the standard webdynpro test component WDR_TEST_MANDATORY. This will be helful.

Best Regards,

Manne.

Former Member
0 Kudos

Hi,

Firstly, change the property state of the dropdown field to required .

Next, place the following code either in WDDOBEFOREACTION or any method created for button actionc depending on your requirement.

DATA: l_view_controller TYPE REF TO if_wd_view_controller.

* Get view controller
  l_view_controller = wd_this->wd_get_api( ).

* Check for mandatory attribute
  cl_wd_dynamic_tool=>check_mandatory_attr_on_view(
  EXPORTING view_controller  = l_view_controller
               display_messages = abap_true
   ).

Now, if the user does not select any value from the dropdown and tries to

perform some action, an error will be raised.

Hope this helps!

Regards,

Radhika.

Former Member
0 Kudos

Yes, but putting just the property do not put the field red-marked when saving without values.

Former Member
0 Kudos

Hi,

for the drop down field set the property state to required