Skip to Content

Calling a JS function from iterator .

Hi All,

How can i call a function written in a page fragment of a BSP application , in the iterator used in the same BSp application. I tried as follows but getting JS error:

Iterator code:

DATA: o_fr TYPE REF TO cl_bsp_find_and_replace,
       o_ip TYPE REF TO cl_htmlb_inputfield,
       o_bee  TYPE REF TO cl_bsp_bee_table.
  DATA: find TYPE string.
  DATA: replace TYPE string.
  DATA: rowno TYPE string ,
        columnno TYPE string ,
        tvid TYPE string .
  CLEAR: find, replace .
WHEN 'DATE' .
find = '<input' .
replace = `< i n p u t   o n c h a n g e = " i s a d a t e ( ) " ` .







 o_fr = cl_bsp_find_and_replace=>factory( find = find
                                                        replace = replace
                                                          mode =  `FIRST_OCCURRENCE` ).



        o_ip = cl_htmlb_inputfield=>factory( id = p_cell_id type = 'date' showhelp = 'X').

        o_ip->value = m_row_ref->date.

        CREATE OBJECT o_bee.
        o_bee->add( level = 1 element = o_fr ).
        o_bee->add( level = 2 element = o_ip ).
        p_replacement_bee = o_bee.

      ENDIF.

The function isadate is written in a page fragment in the same BSP application.

Thanks,

Anubhav.

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Oct 06, 2008 at 10:48 PM

    Hi Anub,

    here is a code fragment that works for me.

      DATA:
            l_str                 TYPE string,
            bee_html              TYPE REF TO cl_bsp_bee_html.
    
        WHEN 'REQ_QTY'.
            l_str = m_page->to_string( value = m_row_ref->req_qty num_decimals = 0 ).
            CREATE OBJECT bee_html.
            bee_html->add(
              html1 = `< i n p u t   t y p e = " t e x t " i d = "`
              html2 = p_cell_id
              html3 = `" c l a s s  =  "urEdf2TxtEnbl urV" value="`
              html4 = l_str
              html5 = `" ` ).
            str = m_row_ref->req_qty.
            bee_html->add(
              html1 = `o n c h a n g e  ="chgqty('`
              html2 = m_row_ref->material
              html3 = `',`
              html4 = l_str
              html5 = `,this)">`
              ).
            p_replacement_bee = bee_html.
    

    Cheers

    Graham Robbo

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Graham,

      Modified IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_CELL_START as:

      DATA: o_ip TYPE REF TO cl_htmlb_inputfield.
      
       WHEN 'DATE' .
            IF p_edit_mode IS NOT INITIAL.
      
      DATA:
              bee_html              TYPE REF TO cl_bsp_bee_html.
      
      o_ip = cl_htmlb_inputfield=>factory( id = p_cell_id type = 'date' showhelp = 'X' ).
      
              o_ip->value = m_row_ref->date.
      CREATE OBJECT bee_html.
              bee_html->add(
                html1 = `<i n p u t   t y p e = " T e x t "   i d = " `
                html2 = p_cell_id
                html3 = `" c l a s s = " u r E d f 2 T x t E n b l   u r V "   v a l u e = " ` 
                html4 = m_row_ref->date
                html5 = `" ` ).
              bee_html->add(
                html1 = `o n c h a n g e = " j a v a s c r i p t : i s i t T o d a y ( ) ; " > ` 
                ).
              p_replacement_bee = bee_html.
      
      
            ENDIF.

      Function isitToday is written in a page fragment in same BSP application.

      In view sourec i get the HTML code as:

      <scrapt languaga="teat/Javascrapt">
      
      f u n c t i o n   i s i t T o d a y (  )   {
      
      a l e r t ( ' i n   f u n c t i o n ' ) ;
      
      }
      </ s c r i p t > 
       
      < i n p u t   t y p e = " T e x t "   i d = " m a t e r i a l _ 1 _ 6 "   c l a s s = " u r E d f 2 T x t E n b l   u r V "   v a l u e = " "   o n c h a n g e = " j a v a s c r i p t : i s i t T o d a y ( ) ;" >

      Still it shows JS Error "Object Expected" when the value of the cell is changed and no popup comes as written in function.

      Also it is not showing the F4 help as Calendar , as i have specified in the Factory method of inputfield.

      Thanks,

      Anubhav.

  • author's profile photo Former Member
    Former Member
    Posted on Oct 10, 2008 at 02:58 PM

    This works for me Fine.

    METHOD if_htmlb_tableview_iterator~render_cell_start.
      DATA: lo_text     TYPE REF TO cl_htmlb_textview,
            lo_link TYPE REF TO cl_htmlb_link,
            lv_link_click TYPE string,
            lv_link  TYPE string,
            lv_dim   TYPE string,
            lv_pernr TYPE string.
    
      FIELD-SYMBOLS: <dat> TYPE ANY.
    
      lv_link  = 'info.htm?pernr='.
      lv_dim   = 'left=300,top=220,width=620,height=200,menubar=0,scrollbars=yes,resizable=no'.
      row_ref = p_row_data_ref.
    
      CASE p_column_key.
        WHEN 'PERNR'.
          CREATE OBJECT lo_link.
          lo_link->id            = p_cell_id.
          lo_link->text          = get_column_value( p_column_key ).
    
          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
            EXPORTING
              input  = lo_link->text
            IMPORTING
              output = lv_pernr.
    
          CONCATENATE `window.open('` lv_link lv_pernr `' , '` lo_link->text `', '` lv_dim `');` INTO lv_link_click.
          lo_link->text = lv_pernr.
          lo_link->onclientclick = lv_link_click.
          p_replacement_bee      = lo_link.
    
        WHEN OTHERS.
          CREATE OBJECT lo_text.
          lo_text->id       = p_cell_id.
          lo_text->wrapping = 'FALSE'.
          lo_text->text     = get_column_value( p_column_key ).
          lo_text->design   =  'STANDARD'.
          p_replacement_bee = lo_text.
      ENDCASE.
    ENDMETHOD.

    -Aman

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi All,

      It might sound strange but instead of writting the JS function code in a page fragment when i wrote it in the main page ie for which i am using the iterator , it is working fine. The code is:

      IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_CELL_START

      DATA: o_fr TYPE REF TO cl_bsp_find_and_replace,
             o_ip TYPE REF TO cl_htmlb_inputfield,
             o_bee  TYPE REF TO cl_bsp_bee_table.
      
      
      WHEN 'DATE' .
            IF p_edit_mode IS NOT INITIAL.
      
              CLEAR : find , replace .
      
              find = '<input' .
              replace = `<i n p u t    on C h a n g e = " i s i t T o d a y ( t h i s . v a l u e ) ; " ` . 
      
              o_fr = cl_bsp_find_and_replace=>factory( find = find
                                                                  replace = replace
                                                                  mode =  `FIRST_OCCURRENCE` ).
      
      
      
              o_ip = cl_htmlb_inputfield=>factory( id = p_cell_id type = 'date' showhelp = 'X' ).
      
              o_ip->value = m_row_ref->date.
      
              CREATE OBJECT o_bee.
              o_bee->add( level = 1 element = o_fr ).
              o_bee->add( level = 2 element = o_ip ).
              p_replacement_bee = o_bee.

      Code in main BSP Page:

      <S C R I P T   l a n g u a g e = J a v a S c r i p t > 
              f u n c t i o n   i s i t T o d a y ( v a l )  { 
              v a r   t o d a y = " < % =   s y - d a t u m   % > " ; 
              m y d t = v a l . s u b s t r i n g ( 6 ) + v a l . s u b s t r i n g ( 3 , 5 ) + v a l . s u b st r in g ( 0 , 2) ;
              v a r   m y v a l u e = t o d a y - m y d t ;
              i f   ( m y v a l u e > 0 )
              {
              a  l e r t ( ' D a t e   o f   r e q u i r e m e n t   m u s t   b  e   i n   f u t u r e ' ) ; 
              }
              }
              < / S C R I P T >

      Thanks all for the help,

      Anubhav.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.