Problem: With an (apex:input type="month) element, I am able to give its value variable a default value within the controller, but it doesn't fill the input appropriately.


<apex:input value="{!monthSelected}" type="month" label="Month" required="true">


public monthSelected {get; set;}    
public ControllerConstructor() {
     monthSelected = '2015-09'; //hardcoded for example

And upon loading:

enter image description here

The "month" input box will only populate when the user manually selects a date. How can I populate it with default values? To be clear, the controller is able to utilize the default value of monthSelected and use it for other portions of the controller right after loading; the problem resides purely in getting the value to show in the box.


1 Answer 1


Figured it out.

The input wants a value of the form YYYY-MM. When you call dateObject.month(), it gives you a number in the form M if the number is single digit or MM if double.

You must give the input a double digit month value, so you must inject some logic to fix dateObject.month() before handing it over to the input component.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .