I am trying to build some help text into a page layout by using a visualforce page. It is very simple (as below). However, I am receiving the error: "(under ) must occur between tags". If I delete the pageblocksection and the inputfield tags. I no longer get the error.
[SalesForce] Visualforce Error (under ) must occur between tags
Related Solutions
On line 1, you have an action set to {!getPackageMap}
. An action function must return "void" or "null" (no value), or a valid PageReference. It cannot return any other data type, or you'll get an error message.
Since you're actually calling that function from apex:repeat
, there's no reason why you need to call the action method. You should remove it from your markup on line 1.
<apex:page standardController="Opportunity_Package__c" extensions="MetadataPackageEditor" <!-- action="{!getPackageMap}" --> >
You need quotes around the DOM id value in the for
attribute selector. You also do not need the $
to apply 'ends with' selector matching, you already know the exact id value of the field being targeted and can use it directly.
You have this:
jQuery("label[for$=" + jQuery(field).attr('id') + "]")
instead you want do this (note the single quotes and the dropped $ modifier):
jQuery("label[for='" + jQuery(field).attr('id') + "']")
which would evaluate like this at runtime and match the label:
(presuming the label actually has a for
attribute on it with this value)
jQuery("label[for='j_id0:j_id106:j_id107:j_id108:j_id117:newContactForm:NewContactAccountSelect']")
Somewhat related, if you add ids to all of the <apex:
tags in your page, you can gain a slightly better looking element id hierarchy - if that is important to you. For example, if you give the <apex:page
tag an id="thePage"
, the first node in the element id value would be thePage
instead of j_id0
.
Also, another question: Is it possible to remove the partialId's added by salesforce and get the actual Id of form element by using javascript, jQuery etc..,?
There is no such thing as a partial ID. Element id values are supposed to be unique in the page. In order to accomplish this when VF renders HTML, the hierarchy of tags in the page are evaluated and the id value of the DOM element is constructed in a way that guarantees uniqueness.
It looks like you have learned about the 'ends with' $
selector modifier but if you want to output the a DOM id value using a VF-native feature, you can do so with the $Component
global function. This will render out the DOM ID of the component into the page.
For instance, if you were to add alert('{!$Component.NewContactAccountSelect}');
to your VF markup and you did it someplace where the renderer could find that component in the hierarchy, in your page source you would see alert('j_id0:j_id106:j_id107:j_id108:j_id117:newContactForm:NewContactAccountSelect');
and have an alert popped with that string value in it.
If $Component.NewContactAccountSelect
couldn't be found in the hierarchy, you'll just get an empty string there in the alert.
Documentation about best practices for referencing component ids in JavaScript: https://developer.salesforce.com/docs/atlas.en-us.salesforce1api.meta/salesforce1api/pages_best_practices_accessing_id.htm
Best Answer
Your
apex:inputField
needs to occur betweenapex:form
tags.The developer console is frankly, kind of terrible, and will hide the tag names when it shows you an error message. Click on the error, and it'll render the html tag names, like below:
Also, next time you post code here, post it as text, so other users can copy that text.