error upon entering ' ,", \ special characters in lwc in ordernotification comment - salesforce

enter image description here
enter image description here
<lightning-layout multiple-rows="true">
<lightning-layout-item if:true={isNotifyCommentsVisible} size="12" padding="horizontal-small">
<lightning-input label="Order Notification Comment"
onchange={handleChangeNotifyComment}
value={updateDistributionWrapper.NotifyComment}
disabled={isNotifyCommentsDisabled}
maxlength="30">
</lightning-input>
</lightning-layout-item>
handleChangeNotifyComment(event) { this.setNotifyComment(event.detail.value);}
controller file
handleClickUpdateOrder(event) {
try {
if (this.updateDistributionWrapper.OrderCwcDescript != 'N' || this.updateDistributionWrapper.ReasonCode != 'WAIT') {
this.updateDistributionWrapper.NotifyWaitForOrder = '';
}
if (this.updateDistributionWrapper.OrderScheduledDate) {
this.updateDistributionWrapper.NotifyComment = '';
}
if(this.updateDistributionWrapper.DistributionMethod === 'D'){
this.newDeliveryComments = this.template.querySelector('[data-id="orderDeliveryComment"]').handleParseComment();
this.newDeliveryComments = this.newDeliveryComments.replace(/\\/g, '');
this.updateDistributionWrapper.OrderDeliverComment = encodeSpecialCharacters(this.newDeliveryComments);
}
Note: we already have method "encodeSpecialCharacters" to encode specail charachter which is workinf fine for deliver comments.
i have already use following code but it did not help:
handleClickUpdateOrder(event) {
try {
if (this.updateDistributionWrapper.OrderCwcDescript != 'N' || this.updateDistributionWrapper.ReasonCode != 'WAIT') {
this.updateDistributionWrapper.NotifyWaitForOrder = '';
}
if (this.updateDistributionWrapper.OrderScheduledDate) {
this.NotifyComment = this.NotifyComment.replace(/\\/g, '');
this.updateDistributionWrapper.NotifyComment=encodeSpecialCharacters(this.NotifyComment);
}
if(this.updateDistributionWrapper.DistributionMethod === 'D'){
this.newDeliveryComments = this.template.querySelector('[data-id="orderDeliveryComment"]').handleParseComment();
this.newDeliveryComments = this.newDeliveryComments.replace(/\\/g, '');
this.updateDistributionWrapper.OrderDeliverComment = encodeSpecialCharacters(this.newDeliveryComments);
}

Related

How does this validation.isElementInArray() in AngularJS works?

Here is my code, where the if condition used that approach.
if( validation.isElementInArray($scope.inputBox, $scope.comments) )
{
$scope.error_msg = " ";
$scope.comments.push($scope.inputBox);
$scope.inputBox = '';
}
else
{
$scope.error_msg = "Name can't be Same";
}
validation.isElementInArray($scope.inputBox, $scope.comments) works same as you do
$scope.comments.indexOf($scope.inputBox) !== -1
Which means that the element $scope.inputBox exist in $scope.comments. Thus, looking at your condition you should be pushing the element in $scope.comments when $scope.inputBox do not exist in it. So, it should be,
if (!validation.isElementInArray($scope.inputBox, $scope.comments)){
$scope.error_msg = ' ';
$scope.comments.push($scope.inputBox);
$scope.inputBox = '';
}
else {
$scope.error_msg = 'Name can\'t be Same';
}

While inserting image check image size and height

When inserting image in angular i want check image width and height.If width and height does not match i give an error
$scope.imageChanged = function(files,selected_creative_size)
{
$scope.backup_creative_size = '';
if (files != null) {
var file = files[0];
//Here i want to check image size and height
if()
{
//Add data into database
}
else
{
$scope.backup_creative_size = 'Please select' + file_prop[0]+' * '+file_prop[1];
}
}
};
Try using this method on the event onChange this will have maximum size as 3 mb
$scope.uplFile = angular.element("input[type='file']")[0].files[0];
if ($scope.uplFile.size < 3145728) {
if ( $scope.uplFile.type == "image/jpg" || $scope.uplFile.type == "image/jpeg") {
//your code
} else {
//your code
}
} else {
//your code
}

How to add thousand separating commas for numbers in angularJS?

I simply want to convert a string of numbers to a number which will be displayed using thousand separated commas.
var value = "123456";
I want to display "123,465" in a grid.
I have looked some documentation on this but everything is about displaying it in HTML.
I want to display this in a dynamic grid.
function numberRenderer (params) {
return new Number (params.value);
}
I want to format the number so that I can convert that into a string for display.
Use a filter ...
HTML usage
{{ number_expression | number : fractionSize}}
Js usage
$filter('number')(number, fractionSize)
I appreciated the answer from #jbrown, but I was also hoping to find some type of solution to add commas to an input field as the user enters numbers. I ended up finding this directive which proved to be exactly what I needed.
HTML
<input type="text" ng-model="someNumber" number-input />
JAVASCRIPT
myApp.directive('numberInput', function($filter) {
return {
require: 'ngModel',
link: function(scope, elem, attrs, ngModelCtrl) {
ngModelCtrl.$formatters.push(function(modelValue) {
return setDisplayNumber(modelValue, true);
});
// it's best to change the displayed text using elem.val() rather than
// ngModelCtrl.$setViewValue because the latter will re-trigger the parser
// and not necessarily in the correct order with the changed value last.
// see http://radify.io/blog/understanding-ngmodelcontroller-by-example-part-1/
// for an explanation of how ngModelCtrl works.
ngModelCtrl.$parsers.push(function(viewValue) {
setDisplayNumber(viewValue);
return setModelNumber(viewValue);
});
// occasionally the parser chain doesn't run (when the user repeatedly
// types the same non-numeric character)
// for these cases, clean up again half a second later using "keyup"
// (the parser runs much sooner than keyup, so it's better UX to also do it within parser
// to give the feeling that the comma is added as they type)
elem.bind('keyup focus', function() {
setDisplayNumber(elem.val());
});
function setDisplayNumber(val, formatter) {
var valStr, displayValue;
if (typeof val === 'undefined') {
return 0;
}
valStr = val.toString();
displayValue = valStr.replace(/,/g, '').replace(/[A-Za-z]/g, '');
displayValue = parseFloat(displayValue);
displayValue = (!isNaN(displayValue)) ? displayValue.toString() : '';
// handle leading character -/0
if (valStr.length === 1 && valStr[0] === '-') {
displayValue = valStr[0];
} else if (valStr.length === 1 && valStr[0] === '0') {
displayValue = '';
} else {
displayValue = $filter('number')(displayValue);
}
// handle decimal
if (!attrs.integer) {
if (displayValue.indexOf('.') === -1) {
if (valStr.slice(-1) === '.') {
displayValue += '.';
} else if (valStr.slice(-2) === '.0') {
displayValue += '.0';
} else if (valStr.slice(-3) === '.00') {
displayValue += '.00';
}
} // handle last character 0 after decimal and another number
else {
if (valStr.slice(-1) === '0') {
displayValue += '0';
}
}
}
if (attrs.positive && displayValue[0] === '-') {
displayValue = displayValue.substring(1);
}
if (typeof formatter !== 'undefined') {
return (displayValue === '') ? 0 : displayValue;
} else {
elem.val((displayValue === '0') ? '' : displayValue);
}
}
function setModelNumber(val) {
var modelNum = val.toString().replace(/,/g, '').replace(/[A-Za-z]/g, '');
modelNum = parseFloat(modelNum);
modelNum = (!isNaN(modelNum)) ? modelNum : 0;
if (modelNum.toString().indexOf('.') !== -1) {
modelNum = Math.round((modelNum + 0.00001) * 100) / 100;
}
if (attrs.positive) {
modelNum = Math.abs(modelNum);
}
return modelNum;
}
}
};
});
AngularJS Directive was found from: AngularJS number input formatted view
https://jsfiddle.net/benlk/4dto9738/
Very appreciative of what Anguna posted. The only thing it was missing for me was handling the decimal places like currency. I wanted it to automatically add 2 decimal places to the displayed value. However, this should only occur on initial display and then again when leaving a field. I updated the code to handle that scenario.
var app = angular.module("myApp", []);
app.directive('currencyInput', function ($filter) {
return {
require: 'ngModel',
link: function (scope, elem, attrs, ngModelCtrl) {
ngModelCtrl.$formatters.push(function (modelValue) {
var displayValue = setDisplayNumber(modelValue, true);
displayValue = setDecimal(displayValue);
return displayValue;
});
// it's best to change the displayed text using elem.val() rather than
// ngModelCtrl.$setViewValue because the latter will re-trigger the parser
// and not necessarily in the correct order with the changed value last.
// see http://radify.io/blog/understanding-ngmodelcontroller-by-example-part-1/
// for an explanation of how ngModelCtrl works.
ngModelCtrl.$parsers.push(function (viewValue) {
setDisplayNumber(viewValue);
return setModelNumber(viewValue);
});
// occasionally the parser chain doesn't run (when the user repeatedly
// types the same non-numeric character)
// for these cases, clean up again half a second later using "keyup"
// (the parser runs much sooner than keyup, so it's better UX to also do it within parser
// to give the feeling that the comma is added as they type)
elem.bind('keyup focus', function () {
setDisplayNumber(elem.val());
});
elem.bind('blur', function () {
// Add Decimal places if they do not exist
var valStr = elem.val().toString();
valStr = setDecimal(valStr);
elem.val(valStr);
});
function setDisplayNumber(val, formatter) {
var valStr, displayValue;
if (typeof val === 'undefined') {
return 0;
}
valStr = val.toString();
displayValue = valStr.replace(/,/g, '').replace(/[A-Za-z]/g, '');
displayValue = parseFloat(displayValue);
displayValue = (!isNaN(displayValue)) ? displayValue.toString() : '';
// handle leading character -/0
if (valStr.length === 1 && valStr[0] === '-') {
displayValue = valStr[0];
} else if (valStr.length === 1 && valStr[0] === '0') {
displayValue = '';
} else {
displayValue = $filter('number')(displayValue);
}
// handle decimal
if (!attrs.integer) {
if (displayValue.indexOf('.') === -1) {
if (valStr.slice(-1) === '.') {
displayValue += '.';
} else if (valStr.slice(-2) === '.0') {
displayValue += '.0';
} else if (valStr.slice(-3) === '.00') {
displayValue += '.00';
}
} // handle last character 0 after decimal and another number
else {
if (valStr.slice(-1) === '0') {
displayValue += '0';
}
}
}
if (attrs.positive && displayValue[0] === '-') {
displayValue = displayValue.substring(1);
}
if (typeof formatter !== 'undefined') {
return (displayValue === '') ? 0 : displayValue;
} else {
elem.val((displayValue === '0') ? '' : displayValue);
}
}
function setModelNumber(val) {
var modelNum = val.toString().replace(/,/g, '').replace(/[A-Za-z]/g, '');
modelNum = parseFloat(modelNum);
modelNum = (!isNaN(modelNum)) ? modelNum : 0;
if (modelNum.toString().indexOf('.') !== -1) {
modelNum = Math.round((modelNum + 0.00001) * 100) / 100;
}
if (attrs.positive) {
modelNum = Math.abs(modelNum);
}
return modelNum;
}
function setDecimal(val) {
// Add Decimal places if they do not exist
var valStr = val.toString();
// If no decimal then add it
if (valStr.indexOf('.') === -1) {
valStr += '.00';
}
else {
var decimalDigits = valStr.length - (valStr.indexOf('.') + 1);
var missingZeros = 2 - decimalDigits;
for (var i = 1; i <= missingZeros; i++) {
valStr += '0';
}
}
return valStr;
}
}
};
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js"></script>
<div ng-app="myApp">
<input type="text" ng-model="myModelValue" currency-input />
</div>

Access to scope variable in custom directive dynamically

I try to write a dynamic field validation. if a check box is checked a new section is shown in my page. As a result, in the new section some new inputs should be filled.
I write a custom directive like this
<input .... multiValidation="Street,City,PostalCode" />
my directive code is
app.directive('multiValidation', function () {
return function (scope, iElement, iAttrs) {
var parts = iAttrs.myvalidate.split(',');
scope.$watch('CustomerModel.Billable', function (val) {
if (scope.CustomerModel.Billable) {
angular.forEach(parts, function (part) {
var element = angular.element('[ng-model="CustomerModel.' + part + '"]');
scope.$watch('CustomerModel.' + part, function (value) {
if (value == null || value == "") {
scope.CustomerForm.$setValidity("CustomerForm", false);
element.addClass("ng-invalid ng-invalid-required");
}
else {
element.addClass("ng-valid ng-valid-required");
var validate = true;
angular.forEach(parts, function (part) {
if (scope["CustomerModel." + part ] == "")
validate = false;
});
scope.CustomerForm.$setValidity("CustomerForm", validate);
}
});
});
} else {
if (scope.CustomerModel.LastName == "" || scope.CustomerModel.LastName == null)
scope.CustomerForm.$setValidity("CustomerForm", false);
if (scope.CustomerModel.LastName != "" || scope.CustomerModel.LastName != null)
scope.CustomerForm.$setValidity("CustomerForm", true);
}
}, true);
};});
my problem is in the following line, I cannot access to the scope variable dynamically in custom directive.
scope["CustomerModel." + part ]
please guide me!!
the CustomerModel is also a variable of $scope. then I load CustomerModel form data base which it contains more property.
I can access to property of CustomerModel like following
$scope.CustomerModel.postalCode
the following way is wrong for dynamically access to them
scope['CustomerModel.postalCode']
the correct way is
scope['CustomerModel']['postalCode']
the whole of code is
app.directive('myvalidate', function () {
return function (scope, iElement, iAttrs) {
var parts = iAttrs.myvalidate.split(',');
scope.$watch('CustomerModel.billable', function (val) {
if (scope.CustomerModel.billable) {
angular.forEach(parts, function (part) {
var element = angular.element('[ng-model="CustomerModel.' + part + '"]');
scope.$watch('CustomerModel.' + part, function (value) {
if (value == null || value == "") {
scope.CustomerForm.$setValidity("CustomerForm", false);
element.addClass("ng-invalid ng-invalid-required");
}
else {
element.addClass("ng-valid ng-valid-required");
var validate = true;
angular.forEach(parts, function (p) {
if (scope['CustomerModel'][p] == "" || scope['CustomerModel'][p] == "undefined" || scope['CustomerModel'][p] == null)
validate = false;
});
if (scope.CustomerModel.customerLastName == "" || scope.CustomerModel.customerLastName == null) validate = false;
scope.CustomerForm.$setValidity("CustomerForm", validate);
}
});
});
} else {
if (scope.CustomerModel.customerLastName == "" || scope.CustomerModel.customerLastName == null)
scope.CustomerForm.$setValidity("CustomerForm", false);
if (scope.CustomerModel.customerLastName != "" || scope.CustomerModel.customerLastName != null)
scope.CustomerForm.$setValidity("CustomerForm", true);
}
}, true);
};
});
and the directive
<div class="panel-body" myvalidate="street,city">

Automatic be bold character string?

On html:
I get a character :
“The Theory of Everything,” may have a few more magic tricks up his sleeve. Sources tell Variety that Redmayne is the favorite to play Newt Scamander in Warner Bros.’ hotly-anticipated “Harry Potter” spin-off, “...
When I will process it by html agility pack(using LINQ) then It be show off:
“The Theory of Everything,” may have a few more magic tricks up his sleeve. Sources tell Variety that Redmayne is the favorite to play Newt Scamander in Warner Bros.’ hotly-anticipated “Harry Potter” spin-off, “...
I want these bold character on html when take down on my app then still keep bold character(or color). Can it be do that?
foreach(var pos in pos_block)
{
//get header, pronunciton
var pronuncationuk=pos.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "sound audio_play_button pron-icon uk");
var pronuncationus=pos.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "sound audio_play_button pron-icon us");
var pos_head = pos.Descendants("span").FirstOrDefault(x => x.GetAttributeValue("class", "") == "pos-head");
////
////
////
var id = pos.Descendants("div").Where(x => x.GetAttributeValue("class", "") == "sense-block");
if(id!=null)
{
foreach(var node in id)
{
result = new ResultToSearch();
var span_h2 = node.Descendants("h2").FirstOrDefault(x => x.GetAttributeValue("class", "") == "");
var sense_body = node.Descendants("div").FirstOrDefault(x => x.GetAttributeValue("class", "") == "sense-body");
if(j==1)
{
if(section_title!=null)
{
result.vocabulary = section_title.InnerText.Trim();
}
if(pronuncationuk!=null)
{
result.pronunciationuk = pronuncationuk.GetAttributeValue("class","");
result.iconuk = "/Photos/uk.png";
}
if(pronuncationus!=null)
{
result.pronunciationus = pronuncationuk.GetAttributeValue("class", "");
result.iconus = "/Photos/us.png";
}
if(pos_head!=null)
{
result.poshead = pos_head.InnerText.Trim();
}
}
if(span_h2!=null)
{
result.senseblockh2 = span_h2.InnerText.Trim();
}
if(sense_body!=null)
{
result.sensebody = sense_body.InnerText.Trim();
}
arrays.Add(result);
j++;
}
//
}
//
j=1;
Try property InnerHtml instead of InnerText.
InnerHtml gets the HTML between the start and end tags of the object.
Whereas InnerText strips all HTML tags and returns the pure text content.

Resources