Is there a way to write a single function to map an object based on the type of control?
For example, I do this for a Yes button:
function YesBtn() { return Aliases.[App].Find("MappedName", "*.btnYes", 5, true); }
Is there a more efficient way to do this so I can find buttons of all types using a single function, rather than mapping each button separately? This is easy enough, but if I can save space and avoid doing this for every single object, I'd prefer to do it that way.
Thank you.
Assuming your framework makes all the MappedName properties have btn in them, then use that in your wildcard:
function allBtns() { return Aliases.[App].Find("MappedName", "*.btn*", 5, true); }
Related
For the functionality I want to add I'm using a couple of different grids on the same page. All these grids should be able to affect what code is executed by the buttons 'delete', 'edit' and 'create'.
In order to seperate the grids I could use their name, but this is rather problematic with the subgrids. The code I'm currently using is as follows:
function deleteButton()
switch(selectedGrid) {
case $("#GridA").data("kendoGrid"):
log("A"); break;
case $("#GridB").data("kendoGrid"):
log("B"); break;
}
selectedGrid has a grid stored that should determine which function to execute.
From this grid I would prefer to extract the model (name) and use that as the switchcase variable. The result would look something like this:
function deleteButton()
switch(selectedGrid.Model) {
case 'modelA':
log("A"); break;
case 'modelB':
log("B"); break;
}
Currently I use logs instead of functions, but the idea is the same. The reason I chose this approach is because multiple grids are using the same model and should call the same case.
Code in the kendo grid for calling the function to set the selectedGrid variable:
.Event(event => event.Change("function(){onRowSelectGrid('grid', 'model');}"))
Code in page js for setting the selectedGrid variable:
function onRowSelectGrid(datagrid, model) {
if (typeof (selectedGrid) !== 'undefined' && selectedGrid !== $("#" + datagrid).data("kendoGrid")) {
//Remove rowselection from the previous grid
selectedGrid.select().removeClass("k-state-selected");
}
var grid = $("#" + datagrid).data("kendoGrid");
selectedGrid = grid;
}
I understand that this is not your every day situation, so if the only solution would be to have seperate buttons for every grid, I would understand that. However, personally I would prefer to have dynamic code that can be used by all grids.
If there are any questions or more explanation is needed, please let me know. If there is a way to do this where the name (including the name of the subgrids) is somehow used, I would definitely want to take a look at such solution.
Oke so this may not be the best solution, but it works. What I did was add a bit to the code saving the selectedgrid.
selectedGrid = grid;
By adding a "model" to the variable to indicate the model of the grid:
selectedGrid.model= model;
This way, when calling the grid from the button, I can call the model variable to indicate what method should be used.
function deleteButton()
switch(selectedGrid.model) {
case 'modelA':
log("A"); break;
case 'modelB':
log("B"); break;
}
Hope this helps anybody running into the same issue.
Is the left over text in input accessible programatically? If so, how?
I only allow tags from autocomplete (to use as search filters), and want to use the left over text as additional keywords, meaning I want to know if it's bound to anything so I can pass it to a search function.
Thanks for the help
That's not directly possible, but you can hack into the directive and make it work by using a helper directive:
app.directive('bindInternalInputTo', function() {
return function(scope, element, attrs) {
var property = attrs.bindInternalInputTo,
input = element.find('input'),
inputScope = input.scope();
inputScope.$watch('newTag.text', function(value) {
scope[property] = value;
});
};
});
Now you can bind some variable in the outer scope to the inner input by doing the following:
<tags-input ng-model="tags" bind-internal-input-to="variable"></tags-input>
Working Plunker
Please note that this solution isn't guaranteed to work with future versions of ngTagsInput since it relies on internal implementation details.
In the ASP MVC page I'm currently working on, the values of three input fields determine the value of a fourth. Zip code, state code, and something else called a Chanel Code will determine what the value of the fourth field, called the Territory Code, will be.
I just started learning jQuery a couple weeks ago, so I would first think you could put a .change event that checks for values in the other two fields and, if they exists, call a separate method that compares the three and determines the Territory code. However, I'm wondering if there is a more elegant way to approach this since it seems like writing a lot of the same code in different places.
You can bind a callback to multiple elements by specifying multiple selectors:
$(".field1, .field2, .field3").click(function() {
return field1 +
field2 +
field3;
});
If you need to perform specific actions depending on which element was clicked, another option would be to create a function which performs the actual computation and then invoke that from each callback.
var calculate = function() {
return field1 +
field2 +
field3;
};
And then invoke this function when on each click:
$(".field1").click(function() {
// Perform field1-specific logic
calculate();
});
$(".field2").click(function() {
// Perform field2-specific logic
calculate();
});
// etc..
This means that you do not repeat yourself.
This works for me
jQuery(document).on('scroll', ['body', window, 'html', document],
function(){
console.log('multiple')
}
);
Adding another possibility, just in cased this may help someone. This version should work on dynamically created fields.
$("#form").on('change', '#Field1, #Field2, #Field3', function (e) {
e.preventDefault();
console.log('something changed');
});
I would like to know how to compose a click mouseevent of different objects in one listener, if ever that's possible.
What I wanted to do is make this listener universal for all the button clicks like:
stage.addEventListener(MouseEvent.CLICK,clicker);
function clicker (e:MouseEvent):void{
if (frame2_btn is clicked){
gotoAndPlay(3);
stage.removeEventListener(MouseEvent.CLICK,clicker);
}
if (frame3_btn is clicked){
gotoAndPlay(4);
stage.removeEventListener(MouseEvent.CLICK,clicker);
}
}
What is the way to do this?
It's really possible to write such function as all event bubbled through hierarchy (upward direction). And you can get the object that is responsible for generating that event using target attribute.
Here's a demo code for your reference ( For Actionscript and Haxe)
stage.addEventListener(MouseEvent.CLICK,clicker);
function clicker (e:MouseEvent):void{
if (e.target.name == "frame2_btn") {
gotoAndPlay(3);
stage.removeEventListener(MouseEvent.CLICK,clicker);
}
if (e.target.name == "frame3_btn"){
gotoAndPlay(4);
stage.removeEventListener(MouseEvent.CLICK,clicker);
}
}
Just make a extra attribute name in your every object( Sprite, shape,...there are many of them) which makes their identification little easier.
Hope this help you
Best Deepak
if you have a simple button, it should work no problem, if it's a movieclip, that acts as a button, then the children will give you a different name.
what do you get when you try
stage.addEventListener(MouseEvent.CLICK,clicker);
function clicker (e:MouseEvent):void{
trace(e.target.name);
}
I am using Knockout Js for my view page. I have a requirement where if any editable field changes, I have to enable Save button else not. This is working nicely.
My issue is I have checkboxes too for each row of item. These are observable items in my viewModel. What happens now is when I check or uncheck any checkbox, Knockout considers that as Dirty item and enables the Save button which I don't want.
How can I tackle this?
I am not sure of the exact code that you are using for a dirty flag, but if it involves using ko.toJS in a dependentObservable like this, then there is a trick that you can use to have it skip some observables.
If you create an observable that is a property of a function, then ko.toJS will not find it.
Here are two examples (someFlag and anotherFlag):
function Item(id, name) {
this.id = ko.observable(id);
//create a sub-observable that the dirty flag won't find
this.id.someFlag = ko.observable(false);
this.name = ko.observable(name);
this.dirtyFlag = new ko.dirtyFlag(this);
//or similarly, place an observable on a plain ol' function
this.forgetAboutMe = function() { };
this.forgetAboutMe.anotherFlag = ko.observable(false);
}
Sample here: http://jsfiddle.net/rniemeyer/vGU88/