cancel
Showing results for 
Search instead for 
Did you mean: 

Making inputfield into readyonly in runtime.

0 Kudos

I have a requirement in which i need to make 2 of my input fields in read only mode during runtime.

I have fetched all details based on Pernr no. and showing all this details in one View. I have a requirement in which based on some conditions i need to make 2 of the fields into readonly mode at runtime so that user would not enter any data into those fields else if those conditions are not satisfied i need to keep those fields open to users so that they can enter data into those fields.

Thanks in advance.

Regards,

Swapnil

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Swapnil,

This is very simple.Take one attribute a_readonly of type WDY_BOOLEAN and bind this attribute to the read only property of the input field.when ever you want to make them read only populate the attribute with value abap_true. Thats all your problem will be solved.

Answers (3)

Answers (3)

0 Kudos

It was easy to modify View using the below Code in WDDOMODIFYVIEW method and this is working fine now..Thought to share with you all people so pasting the code below.

Thanks alot everyone for your precious Help.

data : w_inpfield type ref to cl_wd_input_field.

if wd_comp_controller->MOD = 'MOD'.

w_inpfield ?= view->get_element( 'BEGDA' ).

w_inpfield->set_read_only( 'X' ).

free w_inpfield.

w_inpfield ?= view->get_element( 'ENDDA' ).

w_inpfield->set_read_only( 'X' ).

else .

w_inpfield ?= view->get_element( 'BEGDA' ).

w_inpfield->set_read_only( ' ' ).

free w_inpfield.

w_inpfield ?= view->get_element( 'ENDDA' ).

w_inpfield->set_read_only( ' ' ).

endif.

Regards,

Swapnil

0 Kudos

Hi Thanks lot for the help. i m trying to do this..

I have tried As per Arjun's Solution bu i am geting the error as follows:

No component exists with the name "TEXT".

My requirement in details is as below.

Basically i m fresher to webdynpro-abap and my requirement is as i have discussed above basic thing is i have 2 buttons on view1 change and create.

I pass Button pressed(Change or Click) to View2 based on that in view 2 i have writen Case and called method accordingly.

When i click on change button on of view1 it takes me to veiw2 in which i have 2 input fields shown where user should not be allowed to change data but other fileds he is allowed to modify data.

So i will create one context of type boolean for view2 and then bind the same attribute to my Enabled or readonly property of the inputfield.

and what i have to write in to make it read only at runtime.

Thanks in advance.

regards,

Swapnil

arjun_thakur
Active Contributor
0 Kudos

Hi ,

slight modification in the code is required:


 DATA lo_el_context TYPE REF TO if_wd_context_element.
 DATA ls_context TYPE wd_this->element_context.
  DATA lv_text TYPE wd_this->element_context-READONLY.
 
If <condition>
 
lo_el_context->set_attribute(
    name =  `READONLY` " this is the name of my attribute
    value = abap_true ).
 
else.
 
lo_el_context->set_attribute(
    name =  `READONLY`
    value = abap_false ).
endif.

Do not copy paste my code because it is according to my component. I have given you the code just for reference.

Create an attribute in view 2 and bind it with readonly property and set the value with the help of code wizard. If you set the attribute value as abap_false, it will make the field editable. and if you set the attribute as abap_true, the input field will be in non-editable mode i.e read only. In the WDDOINIT method of view2, use the cose to check the condition and set the attribute value accordingly. Take the help of code give above.

Regards

Arjun

Edited by: Arjun on Jan 22, 2009 6:05 PM

arjun_thakur
Active Contributor
0 Kudos

Hi,

Create a context attribute of WDY_BOOLEAN type and bind it with the ReadOnly property of input field.

Now check your conditions , if it is satisfied set the value of that attribute as abap_true else set it as abap_false.

Refer the code:



 DATA lo_el_context TYPE REF TO if_wd_context_element.
 DATA ls_context TYPE wd_this->element_context.
  DATA lv_text TYPE wd_this->element_context-text.

If <condition>

lo_el_context->set_attribute(
    name =  `READONLY` " this is the name of my attribute
    value = abap_true ).

else.

lo_el_context->set_attribute(
    name =  `READONLY`
    value = abap_false ).
endif.

I hope it helps.

Regards

Arjun

Edited by: Arjun on Jan 22, 2009 5:13 PM

Edited by: Arjun on Jan 22, 2009 5:13 PM