0

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.

Page:

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

Controller:

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.

Thanks

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.