4

For one of the requirements I'm building a visualforce page with a controller. The problem is that I can not save the page with <apex:input> type being number. Compilation error is:

Expected input type 'text', got 'number' for Id data type

It is filled by the value(not the key) of a map in my controller.

Controller code(stripped down to wrapper only and used lines):

public MyWrapperClass wrapper {get; set;}
// More properties
// Constructor, other methods

public class MyWrapperClass {
    public Map<String, Integer> myMap { get; set; }
    // More properties

    public MyWrapperClass(Custom_object__c custObj, List<Custom_object_Child__c> cocs) {
        myMap = new Map<String, Integer>();
        for (Custom_object_Child__c coc : cocs) {
            myMap.put(coc.Unique_Name__c, Integer.valueOf(coc.Number_field__c));
        }
    }
}

VF page:

<apex:repeat var="coc" value="{!wrapper.myMap}">
    <apex:input type="number" value="{!wrapper.myMap[coc]}" />
</apex:repeat>

Is there a workaround to this? I know I can add javascript check on the field to only allow numbers, but I'd like to try to keep javascript to a minimum.


P.S. Please note, that if I change the type="number" to type="text", then the page saves without any problem.

4
  • similar issue here -- salesforce.stackexchange.com/questions/51180/…
    – kurunve
    Commented Jan 17, 2018 at 15:16
  • Try using a function on the controller that returns the value you want instead of trying to get it from the visualforce page.
    – Aequitas
    Commented Jan 17, 2018 at 22:49
  • @Aequitas can you elaborate please?
    – Novarg
    Commented Jan 18, 2018 at 10:45
  • @kurunve indeed. I would even say "same issue", not just similar. But it also does not include code to reproduce it
    – Novarg
    Commented Jan 18, 2018 at 10:46

1 Answer 1

2

You can try to add

docType="html-5.0"

in your balise

apex:page

or you can use standard tag html

<input type="Number">

Hope that help.

1
  • thanks for you answer! I ended up using <input> tag
    – Novarg
    Commented Jan 18, 2018 at 10:42

You must log in to answer this question.

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