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

Visualforce getting and assigning inputField values

Hi everyone,


I'm pretty new to the Salesforce enviroment and even more with Visualforce pages. I'm trying to make an edit page of one of my objects but I want to customize with a button how the values will be assigned.


For example I have to make like a Time Allocation process where I was thinking on having two Datetime inputs one for Start and one for Exit. And that I can with a click of the Start button assign the current time to the respective Datetime field. Also being able to save it and the next time I access that objects record my Start button be Disabled and my Stop button enabled. So that I can click stop and obtain the current time on the Exit Datetime field. Something like this is what I have, which is only the fields and buttons.


Atleast I wanna know how and if I can obtain and assign values to inputFields, and if I can make them un editable when I want to.


<apex:page standardController="Time__c" showHeader="true" tabStyle="Time__c" >
  <apex:form >
  <apex:pageBlock title="Time">
    <apex:pageBlockSection columns="1">
      <apex:inputField id="tStart" value="{!Time__c.Start__c}" />
      <apex:inputField id="tFinish" value="{!Time__c.Finish__c}"/>
      <apex:inputField id="tCase" value="{!Time__c.Caso__c}" />
      <apex:commandButton action=" " value="Start"/>

      <apex:commandButton action="" value="Finish"/>

    <apex:pageBlockButtons >
      <apex:commandButton action="{!save}" value="Save"/>
      <apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>


You'll need to do it in the controller


In the controller have a public property:



public boolean startDisabled { get; set;}  

public PageReference startCount()
	startDisabled = true;
	return null



and set it in the start/stop actions.


Then on your ocmmand buttons


<apex:commandButton action="{!startCount} " value="Start" disabled="startDisabled"/>

 You have to go server side to do all this, nothing native to VF is going to do it in JS only.


When you get more advanced you can look at 'rerender' to do inplace updates without a page refresh (Ajax) or perhaps use @RemoteAction


Best of luck