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.

  • similar issue here -- salesforce.stackexchange.com/questions/51180/… – kurunve Jan 17 '18 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 Jan 17 '18 at 22:49
  • @Aequitas can you elaborate please? – Novarg Jan 18 '18 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 Jan 18 '18 at 10:46
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.

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

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.