I have a field set in SF that I am using in a Visual Force page and the formatting of the field labels is not cooperating exactly.
Here is my code.
<apex:pageblocksection columns="1" title="[...]" collapsible="false">
<apex:repeat value="{!fields2}" var="c">
<apex:inputfield value="{!ghostacc[c.fieldPath]}" required="true" style="white-space: nowrap; position: relative;"/>
</apex:repeat>
</apex:pageblocksection>
The result is a label for the input field that allows for word wrap. Is there something that I am missing?
Thank you!
style attribute on <apex:inputField> applies to the input itself, not the label next to it.
Try explicitly specifying the label and the input, something like this?
<apex:pageBlockSectionItem>
<apex:outputLabel value="{!c.label}" style="nowrap magic goes here">
<apex:inputfield value="{!ghostacc[c.fieldPath]}" required="true" />
</apex:pageBlockSectionItem>
Related
I am new to salesforce environment and I am trying to achieve simple thing. I want to create new Lead screen with custom lead questions and save that as a Lead.
I created apex form, overridden new lead button page, but when I press save button on that page, I dont get any error but it also doesnt save the Lead. Cancel button seems to be working.
Do I need to write custom code for save or apex:pageblockbuttons default action should work ?
I will just show short snippet of the code, as most of it is just setting the input fields
<apex:form id="mySection">
<apex:pageBlock title="New Lead: {!Lead.Name}">
<apex:pageBlockSection title="Lead information" columns="1" >
<apex:inputField value="{!Lead.FirstName}" tabOrderHint="1"/>
<apex:inputField value="{!Lead.LastName}" tabOrderHint="2"/>
<!-- Other fields are skipped -->
<apex:inputField value="{!Lead.Project_Value__c}" tabOrderHint="3"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
I found the solution, which was not related to the apex itself, but more to a one custom field which was mandatory but not on the page. I decided to leave the answer here, because while I was trying to find the solution to this issue, I discovered command which actually shows why the input form failed.
<apex:pageMessages />
Maybe that is a common knowledge to Visualforce, apex users, but for me it was a helpful tool and thats why I decided to leave it in an answer, if someone will have similar issue to remember to add that line.
I have values that need to be setup like this:
Displayed like this, but with four columns:
I tried this way but this a mess... (The above picture is an example and would have USD $ 0.00 inline with the check total):
The code I'm using is:
<apex:page standardController="BookingEvent__c" extensions="EventInclusiveTotalPriceInlineExt" standardStylesheets="true" tabstyle="BookingEvent__c" docType="html-5.0">
<apex:form>
<apex:pageBlock mode="maindetail">
<apex:pageBlockSection columns="4">
<apex:outputfield value="{!be.ForecastRevenue1__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue2__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue3__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue4__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue5__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue6__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue7__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue8__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue9__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue10__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue11__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue12__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue13__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue14__c}"></apex:outputfield>
<apex:outputfield value="{!be.ForecastRevenue15__c}"></apex:outputfield>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
I do not know how to style and it needs to look like it is displayed in the second pic.
Any help would be great, I'm new to VF and not great at styling yet and am having troubles finding exactly what i'm looking for.
For building pretty difficult layouts on Visuaforce page you can use power of HTML and CSS, pretty often it's more convenient than Visuaforce tags.
So, for implementation of table on your first screen I would prefer to use HTML table tag in cells of which apex:outputfield tags were included.
I'm using an inputField that is binded directly to a custom objects field in the controller.
The following will generate a dropdown list with a label.
<apex:inputField value="{!Agency_Profile.Location_Principal_Activity__c}" />
My problem is that I need to add the required mark next to the inputField without losing the label or having default error msgs.
when I used
<apex:inputField value="{!Agency_Profile.Location_Principal_Activity__c}" required="true"/>
I got the required mark but I lost my custom error msgs for validation.
when I used
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:inputField value="{!Agency_Profile.Location_Principal_Activity__c}" />
</apex:outputPanel>
the labels near the dropdown list didnt show anymore..
Is there a way I can accomplish what I need?
I ended up using this.
//this part to add the missing label.
<apex:outputLabel styleclass="labelCol" value="{!$ObjectType.Agency_Profile__c.fields.Location_Principal_Activity__c.Label}" />
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:inputField value="{!Agency_Profile.Location_Principal_Activity__c}" />
</apex:outputPanel>
The best way is to add validation rule for this field for this object.
using raym0nds approach, this is how it looks for a custom controller variable, in my case with the name from a custom field of an object.:
//this part to add the missing label.
<apex:outputLabel for="myId" styleclass="labelCol" value="{!$ObjectType.Agency_Profile__c.fields.Location_Principal_Activity__c.Label}" />
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:inputText id="myId" required="true" value="{!myCustomField}" label="{!$ObjectType.Agency_Profile__c.fields.Location_Principal_Activity__c.Label}" />
</apex:outputPanel>
note the apex:inputText type which now has an label, id and required attribute. The apex:outputLabel now has a for attribute. The for/id is just so clicking on the label will put the cursor into the right field. The required enables form validation, because the rest is just make-up. The label adds a good field name to that validation error - otherwise it would show the internal field id there.
the whole approach is interesting if you have a mass edit table in which all records share certain values (e.g. add multiple leads for the same company)
I have a custom Object called "Gift_c" off the Contact record. I would like to replace the standard "Gift_c" page with a visualforce page so that I can selectively hide certain fields.
All is farily straightforward.
<apex:page standardController="Gift__c" showHeader="true" >
<apex:form >
<apex:pageBlock title="" mode="Edit">
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Basic Information" columns="1">
<apex:inputField value="{!Gift__c.Contact__c}"/>
<apex:inputField value="{!Gift__c.GiftAmount__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
The Challenge:
Normally when you are on a Contact and I click the "New Gift" button and the Contact_c field from the Gift_c object is populated to be the person I just came from. How can I ensure that still happens on the new Visual Force Page
Actually this functionality comes out of the box as long as you override the "New/Edit" button to point to new page.
There is what is known as the lkid hack. It is an undocumented feature that the values for the parent are passed as GET parameters from the New button on a related list. So you could extract the parameters that way, but it is widely accepted that this is a very flimsy solution.
Or there is a very neat solution posted here: hack-to-find-field-ids-allows-a-default-ui-new-page-to-be-pre-populated
This solution is screen scraping the standard edit page for all the lkid values in the html of the page. There are just as many reasons why this could one day just stop working, but it is probably more robust than reverse engineering the get parameters.
I want to display a field in a object to show just the whole number/integer value. This field has decimal values in the structure but for i need to show the integer value for this VF page only.
<apex:pageBlockSectionItem >
<apex:outputLabel value="# Connections" for="Connections"/>
<apex:outputText id="Connections" value="{!Event__c.Total_Connections__c}" />
</apex:pageBlockSectionItem>
No of connections has to be shown as whole number.
thanks
You can use parametrized output with formating, for example:
<apex:outputText id="Connections" value="{0, number, integer}">
<apex:param value="{!Event__c.Total_Connections__c}" />
</apex:outputText>
For more detail about all the formating options, check Java's MessageFormat, the same formating is used for <apex:outputText>