disable the working of save button - salesforce

I have done a VF page in this pages controller. I have written a query to get some record. If the condition is false then an error message is shown. If the error message is shown then I want to disable the working of the save button.
Is it possible to enable the working of save button, or disable a save button? In Apex code.

The disabled attribute of an <apex:commandbutton> can be set to enable/disable a button. Setting this attribute to a bound Apex variable would allow you to control whether or not the button is enabled in your Apex Controller or Extension.
Example Visualforce markup:
<apex:commandbutton action="{!save}" value="Save" id="theButton" disabled="{!myApexBooleanVariable}" />
Example Controller or Extension Apex code:
public Boolean myApexBooleanVariable {get;set;}

Related

To Reset Field using Visualforce page and apex

Hi i am new to visual force i wanted to learn how to reset the field in VisualForce Page
Set immediate="true" on the reset button

Command Button in Visualforce Page

I am using the following lines of code in my VF page to open the URL & it's opening in the same tab but I need to open a new Tab as soon as clicking the custom URL Button?
<apex:commandButton action="{!URLFOR($Action.My_Obj__c.My_custom_link)}" value="My custom button"/>
I don't think I have ever seen a button that opens something as new tab/window? Link yes, but not button. Think if that's really what you want, user might be surprised with unexpected behaviour.
Try using <apex:commandLink action="{!URLFOR($Action.My_Obj__c.My_custom_link)} target="_blank">. You could style it to look like button by looking at class names (both in Classic and Lightning Experience).
If that doesn't work - worst case you can always capture onclick and do window.open or whatever from there...

create simple form with AngularJS+Bootstrap+grid

I am working on AngularJS and Bootstrap. I am new to both. I wanted to create one form which include firstname input textbox,lastname input textbox , city dropdown and add button called addUser.
When I click the add user button it should be saved in our database and then displayed in below grid with edit and delete button. When I click the edit button, all record comes under above corresponding textbox. I have gone through below link but i didn't get my scenario implementation, in that they used xeditable.
http://vitalets.github.io/angular-xeditable/
Here is an form example made with angular link
Basicly you need to create a controller. In your controller create a user object, bind this object properties to form contollers with ng-model. When user clicks a button send user object to a method in your controller, add ng-click to your buttons. In your functions, you can do create, edit, delete actions.
Please refer the link and check the highlighted keywords, this must cover all of your needs.

Reset button is not re-set the form after validation error popup?

I have one form with some fields with submit and reset button. I am using cakephp model validation to validate empty and special characters.
If I enter invalid data and submit the form, its displaying error message.After that I click on reset button,its not reset the form. Before validation error message its working fine.
My reset button code is
<input type="reset" class="uiBtn" value="Reset" name="reset"> <input type="submit" class="uiBtn" value="Save Section" name="">
Also I used jquery reset function, its also not working..
Please any one help me what is the problem???
It doesn't work because HTML Reset buttons reset the controls in a form back
to the value they were when the page first loaded. When you post back, the
PHP engine sets the values of the controls again, so the Reset would do
nothing more than change the controls back to what they were when you loaded
the page after the postback.
The only solution to this is to either do it client-side with javascript or
server-side on a postback. Just iterate through all of your controls and set
their properties appropriately.
Following Js Code would certainly work, assuming you don't have another onload event already set.
window.onload = function () {
for(var f in document.getElementsByTagName("form"))
f.reset();
}
This post might help you to reset the form after submit.

Is it possible to add style to a field in Salesforce?

I have a situation where I need to convert input text to upper case. As soon as we type some text in the input field it needs to convert it to Upper case.
We have following css style for this:
style="text-transform: uppercase"
Using this style, text is entered in Upper case automatically so we don't need to do anything extra, but there is no option in Salesforce to add style to a field.
Is there any way to accomplish this?
Unfortunately, there isn't an easy way to add a CSS style to a field appearing on a Standard Page Layout in edit mode. However, there are some options (listed below) you may want to explore.
Visualforce
You can add a style attribute to an [inputtext] in Visualforce (http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_inputText.htm) or inputfield component.
<apex:inputtext value="{!Widget__c.Name}" style="text-transform:uppercase;" />
To add a CSS class instead, you can use the styleClass attribute. I believe this affects only the display of the text data, though. To make sure the value is uppercase when saved to the database, use this JavaScript on the onkeyup attribute (below).
<apex:inputtext value="{!Widget__c.Name}" style="text-transform:uppercase;" onkeyup="var u=this.value.toUpperCase();if(this.value!=u){this.value=u;}" />
Standard Page Layout
Option 1: Embedding a Visualforce Page in a Standard Page Layout
To do this on a Standard Page Layout, you could create a Visualforce Page for the field you would like this functionality on. This however will show up on View of the record only. It will not be visible on Edit.
The Visualforce Page would look like this (where Widget__c is replaced by the sObject you're working with):
<apex:page standardController="Widget__c">
<apex:form id="WidgetForm">
<apex:actionFunction name="SavePost" action="{!save}" rerender="WidgetPanel" status="str" />
<apex:outputpanel id="WidgetPanel">
<apex:inputtext id="WidgetName" value="{!Widget__c.Name}" style="text-transform:uppercase;" onkeyup="var u=this.value.toUpperCase();if(this.value!=u){this.value=u;}" />
<apex:commandbutton value="Save" styleClass="btn" onclick="SavePost();" />
<apex:actionStatus startText="Loading..." stopText="" id="str"> </apex:actionStatus>
</apex:outputpanel>
</apex:form>
</apex:page>
Then on the Page Layout, click the Visualforce Pages category underneath Fields and Buttons, and add your Visualforce page to your Page Layout by dragging the Visualforce Page component to the Layout. Be sure to configure the height of it by clicking the wrench in the top right of the new Visualforce Page component.
Option 2: Use JavaScript on a Standard Page Layout with a Sidebar Component
Another, more complicated, option for working with a Standard Page Layout would be to add a Home Page Component on the Sidebar that contains JavaScript. This option requires a fair understanding of JavaScript (or jQuery a JavaScript library). The JavaScript could then find the field, add the text-transform:uppercase; style to it, and bind a function to the keyup event to convert all inputted characters to uppercase (element.value.toUpperCase();). For more information on this method, check out Tehnrd's blog post on adding a sidebar component for JavaScript. He uses this method to show and hide buttons on Standard Page Layouts, but it could be modified to suit your purposes.

Resources