cancel
Showing results for 
Search instead for 
Did you mean: 

How to validate input field in a popup view

Former Member
0 Kudos

Hi Experts,

I am having a problem in validating the input fields on a popup.

I have two windows W_MAIN ( views V_MAIN and V_POPUP ) W_POPUP

in View V_MAIN - i have abutton to show the popup screen V_POPUP in window W_popup.

V_POPUP has two input fields PO and PO item - of which PO is a mandatory field.

code in action of button


  data LO_WINDOW_MANAGER type ref to IF_WD_WINDOW_MANAGER.
  data LO_API_COMPONENT  type ref to IF_WD_COMPONENT.
  data LO_WINDOW         type ref to IF_WD_WINDOW.
  data L_API             type ref to IF_WD_VIEW_CONTROLLER.

  LO_API_COMPONENT  = WD_COMP_CONTROLLER->WD_GET_API( ).
  LO_WINDOW_MANAGER = LO_API_COMPONENT->GET_WINDOW_MANAGER( ).
  LO_WINDOW         = LO_WINDOW_MANAGER->CREATE_WINDOW(
                     WINDOW_NAME            = 'W_POPUP'
                     MESSAGE_DISPLAY_MODE   = IF_WD_WINDOW=>CO_MSG_DISPLAY_MODE_SELECTED
                     BUTTON_KIND            = IF_WD_WINDOW=>CO_BUTTONS_OK
                     MESSAGE_TYPE           = IF_WD_WINDOW=>CO_MSG_TYPE_NONE
                     DEFAULT_BUTTON         = IF_WD_WINDOW=>CO_BUTTON_OK
                     ).

  L_API = WD_THIS->WD_GET_API( ).

  LO_WINDOW->SUBSCRIBE_TO_BUTTON_EVENT(
             BUTTON            = IF_WD_WINDOW=>CO_BUTTON_OK
             ACTION_NAME       = 'OK_INSERT'
             ACTION_VIEW       = L_API
             IS_DEFAULT_BUTTON = ABAP_TRUE ).

  LO_WINDOW->OPEN( ).

i have subscribed to button even on the popup view button OK.

in my action onactionok_insert - i am able to get the input field details, but on this action, i want to validate the mandatory input field PO.

How to do that?

I don't want popup view to close on OK if mandatory input is not filled.

Any clue or inputs is highly appreciated. Thanks

Regards,

Ajay

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

In the ONAction of your ok button, you can check for the input fields.

As you said, you have the values of input field in the On Action, now just check whether it is empty or not.

If empty throw an error message.

if input_1 is initial.

<Throw Erro message>

Else

<Close the window>

Former Member
0 Kudos

Hi Saurav,

The method for On action of Ok is in view V_MAIN

If i am validating there, i am already out of Pop up view. any error message thrown there is displayed in V_MAIN and not in the popup view.

I don't want the popup view to close on clicking OK, if mandatory input fields are not filled, and the OK button is created as part of

LO_WINDOW->SUBSCRIBE_TO_BUTTON_EVENT

and not the button in layout of V_POPUP

Hope you have understood the scenario.

Regards,

Ajay

Former Member
0 Kudos

Hi,

U can create action in the pop up window.

In the doinit write the code.

*  set actions to buttons
  DATA lo_view_controller TYPE REF TO if_wd_view_controller.
  lo_view_controller = wd_this->wd_get_api( ).
  DATA lo_wdw_controller TYPE REF TO if_wd_window_controller.
  lo_wdw_controller = lo_view_controller->get_embedding_window_ctlr( ).
  DATA lo_item_popup_window TYPE REF TO if_wd_window.
  lo_item_popup_window = lo_wdw_controller->get_window( ).

    lo_item_popup_window->subscribe_to_button_event(
    button = if_wd_window=>co_button_ok
    button_text = 'otr_text'
    action_name = 'OK'
    action_view = lo_view_controller
    is_default_button = abap_true
  ).

Now u can create action in the pop up window.

Former Member
0 Kudos

hi,

Make the subscrbe to button event in new view only.

For this , get the reference of Pop up window in Wd do init and make the subscrbe to button event there only.

It will work.

Former Member
0 Kudos

Hi Pankaj and Saurav,

As said, i created the action in WDINIT of V_POPUP view and on action OK, i tried to do the mandatory input validation.

but still the error message is not displayed in popup screen but its shown in my V_MAIN view from where the popup is invoked.

My main intention is i want to check input field required on OK button action of popup and don't want to close the popup with if no value is given in the required field.

Rgds,

Ajay

Former Member
0 Kudos

Hi,

You need to explicitly handle the CLOSE action of the popup.

Former Member
0 Kudos

hi,

Ya, its not working.

I would suggest you another alternative.

In the new window which is opening as pop up window, you can make new buttons there as UI elements.

for those buttons, define an action and do all the validation there.

I hope it would help .

Former Member
0 Kudos

In the CREATE WINDOW there is a parameter

CLOSE_IN_ANY_CASE = ABAP_FALSE

First add these parameters and set the above values.

Now you have to create action CLOSE inthe ACTIONS tab.

Using the window(if_wd-window) reference create the action

CALL METHOD lo_window->set_close_button

EXPORTING

close_button = abap_true.

lo_controller= wd_this->wd_get_api( ).

CALL METHOD lo_window->set_on_close_action

EXPORTING

view = lo_controller

action_name = 'CLOSE'. "CLOSE action name

Store the window reference globally in the view.

Now in the CLOSE action,

Using the message manager get the messages.

If you find any messages, then donot allow the close

otherwise close the window using the CLOSE method of if_wd_window.

How are you checking the mandatory nature of the fields....

Regards,

Lekha.

Former Member
0 Kudos

when u have created the window take close in any case parameter also.

lo_window = lo_window_manager->create_window(

window_name = 'WIN2'

message_display_mode = if_wd_window=>co_msg_display_mode_selected

  • close_button = abap_true

button_kind = if_wd_window=>co_buttons_okcancel

message_type = if_wd_window=>co_msg_type_none

default_button = if_wd_window=>co_button_ok

CLOSE_IN_ANY_CASE = abap_false

).

Former Member
0 Kudos

Hi Lekha and Pankaj,

I am encoutering the error while trying to handle close action.

In V_MAIN view i have button - on the button click i have below action

Action on button.


  data LO_WINDOW_MANAGER type ref to IF_WD_WINDOW_MANAGER.
  data LO_API_COMPONENT  type ref to IF_WD_COMPONENT.
  data LO_WINDOW         type ref to IF_WD_WINDOW.
  data L_API             type ref to IF_WD_VIEW_CONTROLLER.

  data: LO_VIEW_CONTROLLER type ref to IF_WD_VIEW_CONTROLLER.

  LO_API_COMPONENT  = WD_COMP_CONTROLLER->WD_GET_API( ).
  LO_WINDOW_MANAGER = LO_API_COMPONENT->GET_WINDOW_MANAGER( ).
  LO_WINDOW         = LO_WINDOW_MANAGER->CREATE_WINDOW(
                     WINDOW_NAME            = 'W_POPUP'
*                  title                  =
                    CLOSE_IN_ANY_CASE      = ABAP_FALSE
                     MESSAGE_DISPLAY_MODE   = IF_WD_WINDOW=>CO_MSG_DISPLAY_MODE_SELECTED
*                  close_button           = abap_true
                     BUTTON_KIND            = IF_WD_WINDOW=>CO_BUTTONS_OK
                     MESSAGE_TYPE           = IF_WD_WINDOW=>CO_MSG_TYPE_NONE
                     DEFAULT_BUTTON         = IF_WD_WINDOW=>CO_BUTTON_OK
                     ).

  L_API = WD_THIS->WD_GET_API( ).

  LO_WINDOW->SUBSCRIBE_TO_BUTTON_EVENT(
             BUTTON            = IF_WD_WINDOW=>CO_BUTTON_OK
             ACTION_NAME       = 'OK_INSERT'
             ACTION_VIEW       = L_API
             IS_DEFAULT_BUTTON = ABAP_TRUE ).

  LO_WINDOW->SET_CLOSE_BUTTON(
    exporting
      CLOSE_BUTTON = ABAP_TRUE ).

  LO_VIEW_CONTROLLER = WD_THIS->WD_GET_API( ).

  LO_WINDOW->SET_ON_CLOSE_ACTION(
  exporting
    VIEW = LO_VIEW_CONTROLLER
    ACTION_NAME = 'OK_INSERT' ).

  LO_WINDOW->OPEN( ).

on the subscribed action OK_INSERT i have the below code


  data LO_WINDOW_MANAGER type ref to IF_WD_WINDOW_MANAGER.
  data LO_API_COMPONENT  type ref to IF_WD_COMPONENT.
  data LO_WINDOW         type ref to IF_WD_WINDOW.
  data L_API             type ref to IF_WD_VIEW_CONTROLLER.

  LO_API_COMPONENT  = WD_COMP_CONTROLLER->WD_GET_API( ).
  LO_WINDOW_MANAGER = LO_API_COMPONENT->GET_WINDOW_MANAGER( ).

  data: LO_ND_PO_DETAILS type ref to IF_WD_CONTEXT_NODE,
      LO_EL_PO_DETAILS type ref to IF_WD_CONTEXT_ELEMENT,
      LO_VIEW_CONTROLLER    type ref to IF_WD_VIEW_CONTROLLER.

  data: LS_PO_DETAILS  type WD_THIS->ELEMENT_PO_DETAILS,
        LS_RET_MESSAGE type APPLMSG,
        LS_DETAIL_LIST type WD_THIS->ELEMENT_DETAIL_LIST.

  data: LC_E type CHAR01 value 'E'.

* navigate from <CONTEXT> to <PO_DETAILS> via lead selection
  LO_ND_PO_DETAILS = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_PO_DETAILS ).

* get element via lead selection
  LO_EL_PO_DETAILS = LO_ND_PO_DETAILS->GET_ELEMENT(  ).

* get all declared attributes
  LO_EL_PO_DETAILS->GET_STATIC_ATTRIBUTES(
    importing
      STATIC_ATTRIBUTES = LS_PO_DETAILS ).

  if not LS_PO_DETAILS-EBELN is initial.

    LO_WINDOW->close( ).
*******here i am not able to close window LO_WINDOW****
*** I am getting dump at LO_window->close saying that access via NULL object reference***
    LS_DETAIL_LIST-EBELN = LS_PO_DETAILS-EBELN.
    LS_DETAIL_LIST-EBELP = LS_PO_DETAILS-EBELP.
* Call to method to insert new line
* that method should return itab with values, these values to be appended with
* existing values of work_list and bind them again to refresh

    WD_ASSIST->SAVE_ENTRIES(
      exporting
        PI_USER_TYPE        = WD_THIS->USER_TYPE
      importing
        PE_L_WA_RET_MESSAGE = LS_RET_MESSAGE
      changing
        PC_L_WA_SAVE_ENTRY  = LS_DETAIL_LIST ).

    if not LS_RET_MESSAGE-TYPE eq LC_E.
    else.
    endif.

  else.
*   get message manager
    data LO_API_CONTROLLER     type ref to IF_WD_CONTROLLER.
    data LO_MESSAGE_MANAGER    type ref to IF_WD_MESSAGE_MANAGER.
    data LV_MSG_ID type STRING.

    LO_API_CONTROLLER ?= WD_THIS->WD_GET_API( ).

    call method LO_API_CONTROLLER->GET_MESSAGE_MANAGER
      receiving
        MESSAGE_MANAGER = LO_MESSAGE_MANAGER.

*   report message
    call method LO_MESSAGE_MANAGER->REPORT_ERROR_MESSAGE
      exporting
        MESSAGE_TEXT             = 'PO input is mandatory'
      receiving
        MESSAGE_ID               = LV_MSG_ID.
  endif.

what is the problem. how to over come this?

i have pasted my code and the way i am handling the close button also, is there anything wrong with using the same action for close as that of OK button action of the popup?

Thanks,

Ajay

Edited by: ajay matam on Oct 6, 2009 4:50 PM

Former Member
0 Kudos

hi,

i cannot understand the code u pasted because the format but in case you want to close your pop up window on the click of

Close button or after doing all validation of OK button , write below code :

It will close the pop up window :

DATA lo_view_controller TYPE REF TO if_wd_view_controller.

lo_view_controller = wd_this->wd_get_api( ).

DATA lo_wdw_controller TYPE REF TO if_wd_window_controller.

lo_wdw_controller = lo_view_controller->get_embedding_window_ctlr( ).

DATA lo_item_popup_window TYPE REF TO if_wd_window.

lo_item_popup_window = lo_wdw_controller->get_window( ).

lo_item_popup_window->CLOSE( ).

Former Member
0 Kudos

Hi,

when you get the window save it globally.

Create a lv_window type ref to if_wd_window under the ATTRIBUTES tab of the view.

Now, In the creation of the popup, you got the window instance right there

wd_this->lv_window = lo_window.

Now use this parameter here.

if not LS_PO_DETAILS-EBELN is initial.
wd_this->lv_WINDOW->close( ). else.
throw error messages.
endif.

Former Member
0 Kudos

Hi Saurav,

I tried to change it but it didn't allow me to realign. sorry for that.

Hi Saurav and Lekha,

I could close the window on click ok button OK as i could get the LO_WINDOW instance created / persisted.

But i have a problem here, i want the window to be closed if we close it by clicking X on the top of the window. but here its not happening and asking user to enter the mandatory data.

How to close the window on pressing close X of the window.

this is how my window has been created


LO_WINDOW         = LO_WINDOW_MANAGER->CREATE_WINDOW(
                     WINDOW_NAME            = 'W_POPUP'
*                  title                  =
                    CLOSE_IN_ANY_CASE      = ABAP_FALSE
                     MESSAGE_DISPLAY_MODE   = IF_WD_WINDOW=>CO_MSG_DISPLAY_MODE_SELECTED
*                     CLOSE_BUTTON           = ABAP_TRUE
                     BUTTON_KIND            = IF_WD_WINDOW=>CO_BUTTONS_OK
                     MESSAGE_TYPE           = IF_WD_WINDOW=>CO_MSG_TYPE_NONE
                     DEFAULT_BUTTON         = IF_WD_WINDOW=>CO_BUTTON_OK        ).

L_API = WD_THIS->WD_GET_API( ).

  LO_WINDOW->SUBSCRIBE_TO_BUTTON_EVENT(
             BUTTON            = IF_WD_WINDOW=>CO_BUTTON_OK
             ACTION_NAME       = 'OK_INSERT'
             ACTION_VIEW       = L_API
             IS_DEFAULT_BUTTON = ABAP_TRUE ).

  LO_WINDOW->SET_CLOSE_BUTTON(
    exporting
      CLOSE_BUTTON = ABAP_TRUE ).

  LO_VIEW_CONTROLLER = WD_THIS->WD_GET_API( ).

  LO_WINDOW->SET_ON_CLOSE_ACTION(
  exporting
    VIEW = LO_VIEW_CONTROLLER
    ACTION_NAME = 'OK_INSERT' ).

  WD_THIS->L_WINDOW = LO_WINDOW.
  LO_WINDOW->OPEN( ).

Rgds,

Ajay

Former Member
0 Kudos

Hi,

As the CLOSE button on the window will trigger this OK_INSERT code. As per the below code

LO_WINDOW->SET_ON_CLOSE_ACTION(

exporting

VIEW = LO_VIEW_CONTROLLER

ACTION_NAME = 'OK_INSERT' ).

Keep the break point and you can check it out....

As this OK_INSERT has the mandatory checks it is showing that.....

Regards,

Lekha.

Former Member
0 Kudos

Hi All,

Many thanks for all your inputs.

I solved this problem. I created popup window with Ok and Cancel buttons and on Cancel i closed the window and on OK i am checking the mandatory input field validation.

Thanks for your help.

Rgds,

Ajay

Answers (0)