How to return the key value from a checkbox list field which automatically updates another field - plugins

I would like it so that when one or more of the options in my checkboxlist has been ticked, the value of said option will then update the amount field.
I'm sort of cheating as I'm using the key value to be the price of the field which I would then like to update the amount field with.
This already works perfectly with the dropdown fields and this does calculate the amount field depending on what has been selected.
As I've had to make the checkboxlist jasonable, the way in which this returns the value is different.
Jobs model:
type_website:
label: Website Package
span: right
type: dropdown
placeholder: '-- Select Website Package --'
trigger:
action: show
condition: value[1]
field: type
type_add_pages:
label: 'Additional Pages'
span: right
type: dropdown
trigger:
action: show
condition: value[1]
field: type
type_addons_get:
label: 'Addons'
span: right
type: checkboxlist
trigger:
action: show
condition: value[1]
field: type
amount:
label: 'Total Amount'
span: left
type: text
readOnly: true
dependsOn:
- type_add_pages
- type_website
- type_addons_get
Jobs.php
protected $jsonable = [
'type_addons_get'
];
public function getTypeAddonsGetOptions()
{
return [
'30' => 'Blog',
'50' => 'Editable Website'
];
}
// Get the value for the amounts field
public function filterFields($fields, $context = null)
{
$typePages = $this->attributes['type_add_pages'];
$typeAddons = array_get($this->attributes, 'type_addons_get');
$typeWebsite = array_get($this->attributes, 'type_website');
return $fields->amount->value = $typeAddons + $typePages + $typeWebsite;
}
As a test, if I just return the following in Jobs.php:
return $fields->amount->value = $typeAddons;
I then get the following result:
Any help would be extremely helpful, thanks in advance!

I will be honest and admit I don't work with the back end forms very often. I actually generate front end systems for clients and myself. So I solved an issue like this with using javascript/jquery in the controller pages (create and update). This is what I think you are trying to do. Here is an example:
Backend in form where I have total price set to read only number input field:
<script>
$('#Form-field-Products-price').change(doThing);
$('#Form-field-Products-set_size').change(doThing);
$('#Form-field-Products-set_color').change(doThing);
$('#checkbox_Form-field-Products-add_ons_1').change(doThing);
$('#checkbox_Form-field-Products-add_ons_2').change(doThing);
$('#checkbox_Form-field-Products-add_ons_3').change(doThing);
function doThing(){
var x = $('#Form-field-Products-price').val();
var y = $('#Form-field-Products-set_color').val();
switch (y) {
case 'silver':
color = 0;
break;
case 'bronze':
color = ".50";
break;
case 'gold':
color = "1.00";
break;
default:
color = 0;
}
var z = $('#Form-field-Products-set_size').val();
switch (z) {
case 'fullset':
size = 0;
break;
case 'partialset':
size = "1.00";
break;
default:
size = 0;
}
if ($('#checkbox_Form-field-Products-add_ons_1').prop('checked') == true)
{
var a = "1.00";
} else
{
var a = 0;
}
if ($('#checkbox_Form-field-Products-add_ons_2').prop('checked') == true)
{
var b = "1.00";
} else
{
var b = 0;
}
if ($('#checkbox_Form-field-Products-add_ons_3').prop('checked') == true)
{
var c = "1.50";
} else
{
var c = 0;
}
$("#Form-field-Products-total_price").val(Number(x) + Number(color) + Number(a) + Number(b) + Number(c) - Number(size));
console.log( Number(x) + ' ' + Number(color) + ' ' + Number(a) + ' ' + Number(b) + ' ' + Number(c) + ' ' + Number(size) );
}
</script>
Here you can see that I am searching the document for these ID's then getting their value. Turning those values into numbers I then push them into the Total Price field.
Here is an adjusted price while filling out the form:

Related

Numbers adding next to each other (ex. 123 + 123 = 123123)

So I have like kind of a homemade economy thing and when I added a working command and when it works it picks a random number and stuff but when it adds the number to the old currency it's adding like for ex 123+123 = 123123 when it supposed to be 246 I don't know how to fix this I tried everything and nothing has worked for me
if (message.content.toLowerCase().startsWith(prefixS.prefix + 'work')) {
const inventoryS = await inventory.findOne({ userID: message.author.id, guildID: message.guild.id });
if (inventoryS.item1 === 'true') {
const payment = Math.floor(Math.random() * 125) + 25;
inventoryS.currency += payment
inventoryS.save()
message.channel.send({ embeds: [new Discord.MessageEmbed().setTitle('After a long day of work your balance is').setDescription(`__Your balance__\n > Money: ${inventoryS.currency}`).setColor('BROWN')] })
}
}
Both of them must be Numbers to do addition, otherwise it will add as strings
inventoryS.currency = parseInt(inventoryS.currency) + parseInt(payment)
it is possible that your inventoryS.currency is a string value
let a = '123' //a string
let b = 123 //an integer
a += b
console.log(a) //logs 123123
you will need to parse it to an integer before adding
let a = '123'
let b = 123
a = parseInt(a) + b
console.log(a)
more references here

Sort table column with custom comparator

I have a table column which displays customers full names (first name + last name). However, I want to sort this column first by first name and then by last name. Therefore I added some comparator function in my controller:
_customNameComparator: function(value1, value2) {
// Separate all words of the full name
var aWordsName1 = value1.split(" ");
var aWordsName2 = value2.split(" ");
// Get the last and first names of the two names
var sFirstName1 = value1.substring(0, value1.lastIndexOf(" "));
var sLastName1 = aWordsName1[aWordsName1.length - 1];
var sFirstName2 = value2.substring(0, value1.lastIndexOf(" "));
var sLastName2 = aWordsName2[aWordsName2.length - 1];
// 0 values are equal
// -1 value1 smaller than value2
// 1 value1 larger than value2
if (sLastName1 === sLastName2) {
if (sFirstName1 === sFirstName2) {
return 0;
} else if (sFirstName1 > sFirstName2) {
return 1;
} else {
return -1;
}
} else if (sLastName1 > sLastName2) {
return 1;
} else {
return -1;
}
}
When the column Header is clicked, I try to call
var aSorter = [];
aSorter.push(new sap.ui.model.Sorter("FullName", bDescending, false, this._customNameComparator));
var oBinding = this.byId("tableTargetGroupDetails").getBinding("items");
oBinding.sort(aSorter);
The comparator does not work like this. The sorting is just as usual (by the full name). What do I do wrong?
And btw: I know that this can lead to some wrong sorting (e.g. for last names containing out of two or more words), but since it's "only" the sorting this is fine for me at the moment.
Unless your binding's operationMode is Client, your comparator will probably not work. You can set the mode where you do your binding using { parameters: { operationMode: 'Client' } }.

Protractor not able to execute else part of my code when element is not displayed/present

I always identify element on my screen with isDisplayed/isPresent and then add if/else to perform further test. But else part of the screen never get executed and get error like "Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator By(css selector, .noga-selected-summary.list.ng-scope.layout-row)" on console log.
Test_PO.js is as follow,
var ProfilePO = function(){
this.Setting = element.all(by.css('.md-icon-button.md-button.md-dark-theme.md-ink-ripple')).get(1);
this.SettingSubMenus = element.all(by.css('.md-tab.ng-scope.ng-isolate-scope.md-ink-ripple'));
//this.ReqProductLabel = element(by.css('[ng-show="ngModel && ngModel.length > 0"]'));
this.BusinessPage = element(by.css('[ng-model="required_categories"]'));
this.AddProductButton = element(by.css('[ng-click="addCategory()"]'));
this.AddedProdCat = element.all(by.css('.noga-selected-summary.list.ng-scope.layout-row'));
this.DeleteAddedProd = element.all(by.css('[ng-click="removeCategory(category)"]'));};
module.exports = ProfilePO;
test_spec.js is as follow,
it('Verify user can add required products on business screen using Find Product or Service Dropdown', function() {
Profile.AddedProdCat.get(0).isDisplayed().then(function(AddedProdCatIsDisplayed){
console.log('Added Prod Cat Is Displayed: ' + AddedProdCatIsDisplayed);
if (AddedProdCatIsDisplayed) {
Profile.AddedProdCat.count().then(function(count){
var Count1 = count;
var C1 = Count1-1;
console.log('Product list has ' + count + ' products');
for (var i=0, j=0; i <= C1 ; i++) {
Profile.DeleteAddedProd.get(j).click();
console.log('deleted ' + (i+1) + ' product');
browser.sleep(2000);
}
});
} else {
FuncLib.NogaList.isDisplayed().then(function(NogaListIsDisplayed) {
console.log('Find Product or Service Dropdown Is Displayed: ' + NogaListIsDisplayed);
if (NogaListIsDisplayed) {
FuncLib.SltNogaCat("A011100"); //select Noga
Profile.AddProductButton.isDisplayed().then(function (AddProdButtonDisplayed){
console.log('Add product button is displayed: ' + AddProdButtonDisplayed);
Profile.AddProductButton.click();
browser.sleep(3000);
Profile.AddedProdCat.isDisplayed().then(function(AddedProdCatIsDisplayed){
console.log('Added Prod Cat Is Displayed: ' + AddedProdCatIsDisplayed);
expect(Profile.AddedProdCat.getText()).toEqual('A011100');
});
});
} else
console.log('Noga Catagory dropdown is not displayed');
});
}
});
});
When"added product category list" is available on screen, this script works nicely but if I don't have added product category list, it returns above mentioned error. I tried using isPresent instead of isDisplayed but still I get same error. Kindly tell me what I need to do to handle this error?
What version of protractor you are using? This should be fixed starting from 3.3.0 - https://github.com/angular/protractor/commit/bd78dfc79b1435d124c994482df6879066079a4d
I think your this.AddedProdCat takes some time to get displayed.
You can use just wait using Expected Conditions for that element, something like this -
it('Verify user can add required products on business screen using Find Product or Service Dropdown', function() {
var EC = protractor.ExpectedConditions;
browser.wait(EC.visibilityOf(Profile.AddedProdCat.get(0)), 5000);
Profile.AddedProdCat.get(0).then(function(firstElement){
console.log('Added Prod Cat firstElement: ' + firstElement);
if (firstElement) {
Profile.AddedProdCat.count().then(function(count){
var Count1 = count;
var C1 = Count1-1;
console.log('Product list has ' + count + ' products');
for (var i=0, j=0; i <= C1 ; i++) {
Profile.DeleteAddedProd.get(j).click();
console.log('deleted ' + (i+1) + ' product');
browser.sleep(2000);
}
});
}
});

Perform auto-search in ionic with MongoDB as backend

The search should be based on the first name and last name. During entering the letters the middle letters from the word should not come. It should come only only from the first name and last name. I got the auto-complete code from code pen and Github but as per requirement I need auto search;
Like:
Auto Search
You should look at creating your own custom directive or using an existing one like this https://github.com/guylabs/ion-autocomplete
This is my code snippet for auto-complete which I used but I need First name and last name Search (It should not search random letters) -
var airlines = [{"fs":"LCI","iata":"LF","icao":"LCI","name":"Lao Central Airlines ","active":true},{"fs":"TGU","iata":"5U","icao":"TGU","name":"TAG","active":true},{"fs":"BT","iata":"BT","icao":"BTI","name":"Air Baltic","active":true},{"fs":"9J","iata":"9J","icao":"DAN","name":"Dana Airlines","active":true},{"fs":"2O","iata":"2O","icao":"RNE","name":"Island Air Service","active":true},{"fs":"NPT","icao":"NPT","name":"Atlantic Airlines","active":true},{"fs":"C8","iata":"C8","icao":"ICV","name":"Cargolux Italia","active":true},{"fs":"FK","iata":"FK","icao":"WTA","name":"Africa West","active":true},{"fs":"8K","iata":"8K","icao":"EVS","name":"EVAS Air Charters","active":true},{"fs":"W8","iata":"W8","icao":"CJT","name":"Cargojet","active":true},{"fs":"JBW","iata":"3J","icao":"JBW","name":"Jubba Airways (Kenya)","active":true},{"fs":"TNU","iata":"M8","icao":"TNU","name":"TransNusa","active":true},{"fs":"HCC","iata":"HC","icao":"HCC","name":"Holidays Czech Airlines","active":true},{"fs":"APJ","iata":"MM","icao":"APJ","name":"Peach Aviation","active":true},{"fs":"TUY","iata":"L4","icao":"TUY","name":"LTA","active":true},{"fs":"LAE","iata":"L7","icao":"LAE","name":"LANCO","active":true},{"fs":"L5*","iata":"L5","icao":"LTR","name":"Lufttransport","active":true},{"fs":"QA","iata":"QA","icao":"CIM","name":"Cimber","active":true},{"fs":"KBZ","iata":"K7","icao":"KBZ","name":"Air KBZ","active":true},{"fs":"L2","iata":"L2","icao":"LYC","name":"Lynden Air Cargo","active":true},{"fs":"MPK","iata":"I6","icao":"MPK","name":"Air Indus","active":true},{"fs":"CAO","icao":"CAO","name":"Air China Cargo ","active":true},{"fs":"BEK","iata":"Z9","icao":"BEK","name":"Bek Air","active":true},{"fs":"IAE","iata":"IO","icao":"IAE","name":"IrAero","active":true},{"fs":"GL*","iata":"GL","name":"Airglow Aviation Services","active":true},{"fs":"ATN","iata":"8C","icao":"ATN","name":"ATI","active":true},{"fs":"GU","iata":"GU","icao":"GUG","name":"Aviateca Guatemala","active":true},{"fs":"GHY","icao":"GHY","name":"German Sky Airlines ","active":true},{"fs":"SS","iata":"SS","icao":"CRL","name":"Corsair","active":true},{"fs":"XK","iata":"XK","icao":"CCM","name":"Air Corsica","active":true},{"fs":"W9*","iata":"W9","icao":"JAB","name":"Air Bagan","active":true},{"fs":"Z8*","iata":"Z8","icao":"AZN","name":"Amaszonas","active":true},{"fs":"D2","iata":"D2","icao":"SSF","name":"Severstal Aircompany","active":true},{"fs":"SNC","iata":"2Q","icao":"SNC","name":"Air Cargo Carriers","active":true},{"fs":"PST","iata":"7P","icao":"PST","name":"Air Panama","active":true},{"fs":"VV","iata":"VV","icao":"AEW","name":"Aerosvit Airlines","active":true},{"fs":"UJ","iata":"UJ","icao":"LMU","name":"AlMasria","active":true},{"fs":"9U","iata":"9U","icao":"MLD","name":"Air Moldova","active":true},{"fs":"NF","iata":"NF","icao":"AVN","name":"Air Vanuatu","phoneNumber":"678 238 48","active":true},{"fs":"NJS","iata":"NC","icao":"NJS","name":"Cobham Aviation","active":true}];
airlines = airlines.sort(function(a, b) {
var airlineA = a.name.to();
var airlineB = b.name.toLowerCase();
if(airlineA > airlineB) return 1;
if(airlineA < airlineB) return -1;
return 0;
});
console.log(airlines);
angular.module('ionicApp', ['ionic'])
.factory('FlightDataService', function($q, $timeout) {
var searchAirlines = function(searchFilter) {
console.log('Searching airlines for ' + searchFilter);
var deferred = $q.defer();
var matches = airlines.filter( function(airline) {
if(airline.name.toLowerCase().indexOf(searchFilter.toLowerCase()) !== -1 ) return true;
})
$timeout( function(){
deferred.resolve( matches );
}, 100);
return deferred.promise;
};
return {
searchAirlines : searchAirlines
}
})
.controller('MyCtrl', ['$scope', 'FlightDataService', function($scope, FlightDataService) {
$scope.myTitle = 'Auto Complete Example';
$scope.data = { "airlines" : [], "search" : '' };
$scope.search = function() {
FlightDataService.searchAirlines($scope.data.search).then(
function(matches) {
$scope.data.airlines = matches;
}
)
}
}]);

Set Time Range of a Zend Dojo TextTimeBox

Hi is it possible to set the time range of a Dojo textTimeBox to 09:00 - 18:30.
I can't find anything in either the Zend or Dojo documentation that show how this can be done or if it can be done.
Many thanks in advance.
You can set max and min constraints for widget:
new dijit.form.TimeTextBox({
name: "prog_val",
value: new Date(),
constraints: {
timePattern: 'HH:mm:ss',
clickableIncrement: 'T00:15:00',
visibleIncrement: 'T00:15:00',
visibleRange: 'T01:00:00',
min:'T09:00:00',
max:'T18:30:00'
}
},
"prog_val");
It does not allow the user to enter data beyond the allowed values.
However this still allows user to scroll to the disabled times, user just cannot select them.
For hiding disabled times you should do some hack :)
You should override _getFilteredNodes method of dijit._TimePicker. For example :
dojo.declare("my._TimePicker", dijit._TimePicker, {
// extend the default show() method
_getFilteredNodes: function (/*number*/start, /*number*/maxNum, /*Boolean*/before) {
// summary:
// Returns an array of nodes with the filter applied. At most maxNum nodes
// will be returned - but fewer may be returned as well. If the
// before parameter is set to true, then it will return the elements
// before the given index
// tags:
// private
var nodes = [], n, i = start, max = this._maxIncrement + Math.abs(i),
chk = before ? -1 : 1, dec = before ? 1 : 0, inc = before ? 0 : 1;
do {
i = i - dec;
var date = new Date(this._refDate);
var incrementDate = this._clickableIncrementDate;
date.setHours(date.getHours() + incrementDate.getHours() * i,
date.getMinutes() + incrementDate.getMinutes() * i,
date.getSeconds() + incrementDate.getSeconds() * i);
if (!this.isDisabledDate(date)) {
n = this._createOption(i);
if (n) { nodes.push(n); }
}
i = i + inc;
} while (nodes.length < maxNum && (i * chk) < max);
if (before) { nodes.reverse(); }
return nodes;
}
});
And you need to set this new class ('my._TimePicker') as a popupClass property of your text time box:
dojo.addOnLoad(function () {
dijit.byId("prog_val").popupClass = "my._TimePicker";
});
And you can see : it works!