function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sonatinesonatine 

dynamic inputText

hi guys,

i have a requirement to make a dynamic inputText, where it should disabled or enabled according to the value of a checkbox field in an object, for example:

 

<apex:inputText value="{!My_Object__c.Quantity__c}" disabled="{!My_Object__c.Disable__c}" />

 

where Disable__c field is a checkbox field.

 

 

but i keep getting this error when i try to insert the My_Object__c.

 

 

<apex:inputText> element value must resolve to a String type!

 

 


can anyone help me with this?

thank you in advance.

 

 

Regards,

 


Best Answer chosen by Admin (Salesforce Developers) 
CLKCLK

<apex:inputField value="{!My_Object__c.Quantity__c}" rendered="{!Not(My_Object__c.Disable__c)}" />

<apex:outputField value="{!My_Object__c.Quantity__c}" rendered="{!My_Object__c.Disable__c}"/>

 

This will solve ur problem.

 

All Answers

CLKCLK

You can't bind object field to inputtext component.

For direct binding to object field use inputField or output field component.

plz go through Visualforce developer guide -> Standard Component Reference.

sonatinesonatine

hey CLK thanks for your reply.

 

how if its just a variable in my apex class? i only need the Quantity__c value for calculation.

the point is, i want to know how to get a dynamic input text box.

so that when Disable__c = true, the user will be able to edit the Quantity text box.

but if Disable__c = false, user must not be able to edit the value, but we still want to display it.

 

 

Regards,

Imran MohammedImran Mohammed

Make use of disabled attribute in inputText tag

disabled="{!IF(objectvariable.disable__c = true, true, false)}"

CLKCLK

<apex:inputField value="{!My_Object__c.Quantity__c}" rendered="{!Not(My_Object__c.Disable__c)}" />

<apex:outputField value="{!My_Object__c.Quantity__c}" rendered="{!My_Object__c.Disable__c}"/>

 

This will solve ur problem.

 

This was selected as the best answer
Pradeep_NavatarPradeep_Navatar

You can do this through repeater control for generating dynamic input text :

 

     <apex:page controller="cls_dynamicrow">

            <apex:form >

            <apex:outputPanel>

            <apex:repeat value="{!propLstQuesAns}" var="varLQA">

            <p>

            <apex:inputtext value="{!varLQA.propAns}" id="textques"/></p>

            </apex:repeat>

            </apex:outputPanel>

            <apex:commandButton action="{!DynamicRow}" reRender="refreshdata" value="ADD ROW"/>

            </apex:form>

      </apex:page>

sonatinesonatine

hi all, thanks for your replies.

thanks again CLK, i forgot that we can use the disabled properties to display/hide the output/input field.

 

and i found out if we have to use the inputText, the value of element "value" must be String, then it will work.

 

mmrrmmrr

This is an simple and excellent solution, without getter/setter.

I have a picklist field, and if the value selected by the user is 'Prospect', another input field should be enabled / shown.

Can you help me in this?