Visualforce - Using Javascript for mandatory fields - salesforce

Team,
I am working on a Salesforce Visualforce page using Javascript to validate mandatory fields - both picklist and text fields. I tried using html required = true but that won't work because I have two functionalities - save link and submit button - on my visualforce page. I would like the user to get an error if they try to submit and the required fields are null/blank. Below is my code but it's not working.
<script>
function submitOnClick(objSubmitBtn){
var RevPL = document.getElementById('RevPL').value;
if(RevPL == null || RevPL == ''){
alert('Review needed.')
return false;
}
var StatusPL = document.getElementById('StatusPL').value;
if(StatusPL == null || AdhStatusPL == ''){
alert('Status needed.')
}
var StatusPL = document.getElementById('Notes').value;
if(StatusPL == null || AdhStatusPL == ''){
alert('Please add notes.')
}
if(confirm('Are you sure you want to submit?')){
objSubmitBtn.disabled = true;
objSubmitBtn.value = 'Submitting... Please Wait';
doSubmit();
}
}
</script>
<apex:form id="PRDetails">
<table width="100%">
<tr>
<td width="50%">
3. Review of documentation
<b> <apex:outputText value="{!PR['Review__c']}" rendered="{!PR['Status__c']='Complete'}"/> </b>
<apex:inputField value="{!PR['Review__c']}" rendered="{!PR['Status__c']!='Complete'}" id="RevPL" />
</td>
</tr>
</table>
<br/>
<table width="100%">
<tr>
<td width="50%">4. Status
<b> <apex:outputText value="{!PR['Status__c']}" rendered="{!PR['Status__c']='Complete'}" /></b>
<apex:inputField value="{!PR['Status__c']}" rendered="{!PR['Status__c']!='Complete'}" id="StatusPL" />
</td>
</tr>
<tr>
<td class="padding">Notes:</td>
</tr>
<tr>
<td class="padding">
<b> <apex:outputText value="{!PR['Notes__c']}" rendered="{!PR['Status__c']='Complete'}"/> </b>
<apex:inputField styleClass="inputLTextbox" value="{!PR['Notes__c']}" rendered="{!PR['Status__c']!='Complete'}" id="Notes"/>
</td>
</tr>
</table>
<table align="center">
<tr>
<td>
<apex:repeat value="{!PR}" var="PR">
<apex:commandButton value="Submit" style="background: #1895c1; color: #FFFFFF; width: 150px;" onclick="submitOnClick(this);" rendered="{!PR['Status__c'] !='Complete'}"/>
</apex:repeat>
<apex:actionFunction name="doSubmit" action="{!submitPR}" />
</td>
</tr>
</table>
<table width="100%">
<tr>
<td style="text-align:right;"><apex:commandLink action="{!savePR}" value="Save" id="SaveLink" style="text-decoration:none; color:blue;"/></td>
</tr>
</table>
</form>

1) You've got
var StatusPL
Declated twice.
2) Visualforce generates IDs in it's own way (adds hierarchy to it) - your "getElementById" won't work, you need to do something else - do an inspect on your page in browser. Maybe add classes and use getElementByClass instead?

Related

How do I get all results where at least one property contains the parameter passed in the filter? (angullarjs)

I am trying to convert my paginated table from individual columns to a search all columns that contain the result.
//Newly added input that I want to query all columns
<input type="text" ng-model="searchCriteria" />
<table ng-table="tableParams" class="table table-condensed" show-filter="true">
<tr ng-repeat="memberInfo in $data">
<td data-title="'Name'" filter="{ Name: 'text'}" sortable="'Name'">
{{memberInfo.Name}}
</td>
<td data-title="'Location'" filter="{ Location: 'text'}" sortable="'Location'" style="width: 275px;">
{{memberInfo.Location}}, {{memberInfo.country}}
</td>
<td data-title="'Phone'" >
{{memberInfo.Phone}}
</td>
<td data-title="''" style="width: 30px;">
<button type="button" class="btn btn-xs btn-info" title="View on map" ng-click="goToMarker(memberInfo.Key)">Map</button>
</td>
</tr>
</table>
Above you can see I have each column has it's own filter, but I want to remove them and have a single catch all.
I have added a screen shot below of a visual mockup
Thank you.
UPDATE
I got the filters to work, but not with the pagination...
<input type="text" class="form-control" placeholder="Search name, phone, or location" ng-model="queryFilter" />
<table ng-table="tableParams" class="table table-condensed" show-filter="true">
<tr ng-repeat="memberInfo in $data | filter:query">
<td data-title="'Name'" sortable="'Name'">
{{memberInfo.Name}}
</td>
<td data-title="'Location'" sortable="'Location'" style="width: 275px;">
{{memberInfo.Location}}, {{memberInfo.country}}
</td>
<td data-title="'Phone'" >
{{memberInfo.Phone}}
</td>
<td data-title="''" style="width: 30px;">
<button type="button" class="btn btn-xs btn-info" title="View on map" ng-click="goToMarker(memberInfo.Key)">Map</button>
</td>
</tr>
</table>
And in the controller I have added this method
$scope.query = function (memberInfo) {
return memberInfo.Name.toLowerCase().indexOf($scope.queryFilter.toLowerCase()) !== -1
|| memberInfo.Location.toLowerCase().indexOf($scope.queryFilter.toLowerCase()) !== -1
|| memberInfo.Phone.toLowerCase().indexOf($scope.queryFilter.toLowerCase()) !== -1
|| memberInfo.Country.toLowerCase().indexOf($scope.queryFilter.toLowerCase()) !== -1
;
};

How do I add a download button for a preview page in react

I am confused on how to add a button to a preview form page in react, such that a user can download the page for reference.
function PreviewMain({
mdaEnroll,
passport,
bloodGroup,
nokPhone,
selectedFacility,
myDate,
enrollmentId,
}) {
return (
<div >
<img
src={URL.createObjectURL(passport)}
alt={"passport"}
width={200}
height={200}
/>
<table >
<thead></thead>
<tbody>
<tr>
<td>Name: </td>
<td >
{mdaEnroll?.name}
</td>
</tr>
<tr>
<td>Blood Group: </td>
<td>
{bloodGroup}
</td>
</tr>
<tr>
<td>Next of Kin contact: </td>
<td >
{nokPhone}
</td>
</tr>
<tr>
<td>Enrollment Id: </td>
<td>
{enrollmentId}
</td>
</tr>
</tbody>
</table>
<h3>
<i>please print this page for reference</i>
</h3>
<button >Download</button>
</div>
);
}
export default PreviewMain;
I'm struggling to find similar implementation. The user onClick the download button should be able to get the table in pdf format. i'll appreciate any help

Update row in Angular JS

I am submiting a form using Angular JS and Web service. Here is code-
<table>
<tr>
<td style="text-align: right;">Name :
</td>
<td>
<input type="text" id="txtEmpName" ng-model="EmpName" />
</td>
</tr>
<tr>
<td style="text-align: right;">Age :
</td>
<td>
<input type="text" id="txtEmpAge" ng-model="EmpAge" />
</td>
</tr>
<tr>
<td style="text-align: right;">City :
</td>
<td>
<input type="text" id="txtEmpCity" ng-model="EmpCity" />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input type="submit" id="btnSubmit" value="Submit" />
</td>
</tr>
</table>
I want to make these text boxes reusable on Edit i.e. on edit click corresponding rows item must be filled and the Save button should now be working like Update button.
How can I do it?
Alternatively How can I make row editable?
Ideally you would wanna create the models as
Employee.Name , Employee.Age , Employee.City
Now
<table>
<tr>
<td style="text-align: right;">Name :
</td>
<td>
<input type="text" id="txtEmpName" ng-model="Employee.Name" />
</td>
</tr>
<tr>
<td style="text-align: right;">Age :
</td>
<td>
<input type="text" id="txtEmpAge" ng-model="Employee.Age" />
</td>
</tr>
<tr>
<td style="text-align: right;">City :
</td>
<td>
<input type="text" id="txtEmpCity" ng-model="Employee.City" />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<button type="button" id="btnSubmit" ng-click="saveEmployee()">{{Employee.id ? "Edit" : "Create"}}</button>
</td>
</tr>
</table>
In the Controller
$scope.saveEmployee = function(){
if($scope.Employee.id){
// Id will be present for a existing employee
// update the Employee
}else {
// Id not present
// create the employee
}
}
I would have an Employee.save() in the model which can identify weather to save or update the Employee

How to display "No data" message using AngularJS?

The code looks as following:
<table>
<tr ng-repeat="action in actionList">
<td></td>
...
</tr>
<tr ng-show="!actionList.length">
<td>
No data.
</td>
</tr>
</table>
This works, but not in way I want because it initially displays "No data" message. I need to display nothing initially and the table with data if actionList.length is not 0. If actionList.length is 0 then display "No data" message, but not as a part of table.
Update:
I've added in my controler:
$scope.isButtonClicked = false;
$scope.queryResult = function () {
$scope.isButtonClicked = true;
$scope.actionList = [];
$scope.actionsQuery.resetPage();
appendPage();
};
But, "No data." message appears on every click. When there's some data it appears very shortly and disappears and when there's no data, it appears correctly.
Why you confusing? Lot of way of you can think to solve this.
Try this simple way
<table>
<tr ng-show="actionList.length!=0" ng-repeat="action in actionList">
<td></td>
...
</tr>
<tr >
<td ng-show="actionList.length==0">
No data.
</td>
</tr>
</table>
Update 1:-
Also you need to check actionList is undefined or null
And You should $scope.actionList is a array
You can check the actionList is null or undefined with ng-if Statement (try with ng-if instead of ng-show in the div tag)
Something like this below way
<div ng-show="actionList !='null' && actionList !='undefined'">
<table>
<tr ng-show="actionList.length!=0" ng-repeat="action in actionList">
<td></td>
...
</tr>
<tr >
<td ng-show="actionList.length==0">
No data.
</td>
</tr>
</table>
</div>
<div ng-show="actionList =='null'|| actionList =='undefined'">
No data.
</div>
Update 2 :-
Another simple way to instead of my update 1
try this below code.
<table>
<tr ng-show="actionList!='undefined' && actionList!='null' && actionList.length!=0" ng-repeat="action in actionList">
<td></td>
...
</tr>
<tr >
<td ng-show="actionList=='undefined' ||actionList=='null' || actionList.length==0 ">
No data.
</td>
</tr>
</table>
Here you can try with ng-if instead of ng-show
Update 3:
I want because it initially displays "No data" message. I need to display nothing initially and the table with data if actionList.length is not 0. If actionList.length is 0 then display "No data" message, but not as a part of table.
So Simple ...
Create a new Boolean Scope variable like a named as IsButtonClick
Globally declare $scope.IsButtonClick==false
Set $scope.IsButtonClick==true on your button click event
Then copy past this below code instead of your html code.
<div ng-show="IsButtonClick">
<table>
<tr ng-show="actionList!='undefined' && actionList!='null' && actionList.length!=0" ng-repeat="action in actionList">
<td></td>
...
</tr>
</table>
</div>
<div ng-show="IsButtonClick"> <span ng-show="actionList=='undefined' ||actionList=='null' || actionList.length==0 "> No data.</span> </div>
Update 4 :
But, "No data." message appears on every click. When there's some data it appears very shortly and disappears and when there's no data, it appears correctly
try this way
$scope.queryResult = function () {
$scope.isButtonClicked = false;
$scope.actionList = [];
$scope.actionsQuery.resetPage();
appendPage();
if($scope.actionList.Length==0)
{
$scope.isButtonClicked = true;
}
};
and the html is
<div ng-show="IsButtonClick">
<table>
<tr ng-show="actionList!='undefined' && actionList!='null' && actionList.length!=0" ng-repeat="action in actionList">
<td></td>
...
</tr>
</table>
</div>
<div ng-show="IsButtonClick"> <span ng-hide="actionList !='undefined' || actionList!='null' || actionList.length!=0 "> No data.</span> </div>
Try this :
<div ng-switch="!!actionsList.length">
<div ng-switch-when="true">
<table>
<tr ng-repeat="...">
<td> ... </td>
</tr>
</table>
</div>
<div ng-switch-when="false">
No data
</div>
</div>
try to put
<tr ng-show="!actionList.length">
<td ng-bind="noData">
</td>
</tr>

How to set dynamic data-title in ngtable (angular plugin)

I want have a multi language view with an ngTable. For do that, i set in my controller a $scope.translate (a valid json) who contains my traductions. In my view i want set my data-title like {{translate.code}} etc...
my view :
<table ng-table="tableParams" class="table ng-table-responsive">
<tr ng-repeat="product in $data">
<td data-title="'{{translate.code}}'" > <!-- display : {{translate.code}} -->
{{product.code}}
</td>
<td data-title="['translate.reference']" > <!-- display : empty -->
{{product.reference}}
</td>
<td data-title="'Label'" >
{{product.label}}
</td>
<td data-title="'Size'" ng-show="manageSizeColor == true">
{{product.size}}
</td>
<td data-title="'Quantity'" >
<ac-quantity minquantity="1" cquantity="product.quantity"></ac-quantity>
</td>
<td data-title="'Price'">
<b>{{product.price + currency}}</b>
</td>
</tr>
</table>
If you're using angularjs ~1.2 with angular-translate ~2.6.1, translation on data-title works like this:
<td data-title="'MY_TRANSLATION_ID' | translate" >
{{product.reference}}
</td>
I' ve finally found how do this, with this example :
https://github.com/esvit/ng-table/issues/53
<td data-title="translate['reference']" >
{{product.reference}}
</td>
where translate is the scope variable and ['reference'] is the property
you can also do this :
<td data-title="getColumnName('your.translate.code')">{{ resultat.number }}</td>
with in your controller :
$scope.getColumnName = function(column) {
return $translate.instant(column);
}

Resources