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
bolaurent.ax1262bolaurent.ax1262 

inputField and default values

I have a VF page that contains an inputfield tag for a picklist. The picklist is defined so that one of the values is the default value.

 

If I create the record in apex, and display it with VF, the field shows up with the default value already set. The documentation states "Beginning with API version 20.0, an inputField matched to a field with a default value has the default value prepopulated on the Visualforce page."

 

However, I want to set the field to Null in apex, and not have any default. 

How can I accomplish this? I tried setting the version to 19, and that worked, but it seems a bit fragile. Do I need to add some js to change the default value in the VF page?

 

bob_buzzardbob_buzzard

Do you have a customer/extension controller for the page?  If so, you could try nulling the field backing the input in the controller.  If that doesn't work, I tend to create my own selectlist backed by a property in the controller so that I can set it to whatever I like.

bolaurent.ax1262bolaurent.ax1262

I do have a controller, and nulling the field did not work. Nor did setting it to ''.

bob_buzzardbob_buzzard

That smacks that VF is overriding the field value.  Can you create your own selectlist and back that with a controller property? You'll have to figure out the available values is the only thing - the describe functionality allows you to do that as long as its not record type specific.