I am in a situation to write some client side validation. For example, in a page I use a Repeater control which creates a list of item. There we could select number of items using a check box (in the first column). So if I click 'Delete' button, the selected cases will be deleted. So I need to check if the selected item's count is zero or not. So my question is, where should I write this kind of validations ? In a common .js file or in the page itself.
This should be done in a separate file. You will encounter times when you will need to have the id of the control being validated for one reason or another so you should provide a manner within that file to receive those ids (parameter name in a function, global variable (not recommended), custom namespace object).
Definitely in a separate js file. Then you could reuse the logic on another similar page.
Best practice suggests that you should place this in a separate file. Personally, I would always write this kind of validation server-side, not javascript, especially if the resulting action is a delete.
I would use javascript to allow for a "select all" feature and I would use jQuery to create an "Are you sure" prompt.
Related
In Struts2 I have successfully implemented an updateErrorCount() method that updates a class member variable every time addActionError() is called through out various action classes. I can then access that variable with a property tag in the associated jsp. However, I am looking for a better solution.
Since the s:actionerror tag lists all of the errors added, is there a way to use an iterator tag or some other solution to display the error count along with all of the error messages right in the jsp?
I thought about overriding addActionError() to avoid having to call an additional method to keep an error count but if I could simply do it all in the jsp it seems much cleaner.
getActionErrors returns a collection, why can't you just call size on that?
I see few legitimate reasons to implement any of this functionality manually.
If you have specific needs you should enumerate them in your question, otherwise I don't see the point of doing this on your own.
I've written some code for custom entities that dynamically presents questions that the user must answer. The code creates answer records, that are then associated with it's parent record.
My issue is that I'd like users to be able to complete the answers BEFORE having to save the record for which they are answering the questions. The problem is that in order to associate the answers records to a parent record, the parent record must have a guid value, and this is only created once the record is saved.
My idea is that I can store the answer record guid values in a global array, and OnSave of the parent record, go update the answer records accordingly to link them to the parent. BUT when I save the record, my global gets wiped clean.
Is there any way to preserve the values stored in that global array? Or does anyone have a more clever way to route around this issue? Thanks very much for any help.
Keeping in mind that you're using a HTML Web Resource and you will have access to the Global Context, I can think in these alternatives:
Force the user to manually save the record: I know that you want to avoid this option, but this behaviour would be similar to the one that the grids have (they show a message which says "To enable this content, save the record"). You can accomplish this using the Form Type.
Save the temporary data in a hidden field: instead of using a global array to save the answers you can use a hidden field in your parent entity so the data will be preserved. You will be able to create the related entities when the form loads again (to reuse the code that you have in place now) or use a plugin (Post Create of your parent entity).
I am putting together a front end for a shopping basket, and it uses a Javascript API to communicate with the database. I have methods such as:
updatePackageQuantity
updateProductQuantity
removePackage
reinstatePackage
Each of the methods require various arguments to be passed, and I'm currently figuring out the best way of retrieving them from the page and passing them.
For example, I currently use classes like this:
Update Quantity
and I'd grab the value from the input field in this instance. I also have 'constants' that I need to pass such as basketID, shopID etc, and I'd like to be able to grab them from the markup somehow.
What would be the ideal way of achieving this? Maybe having a hidden form on the page with a list of inputs, or could I attach the values to attributes, similar to the way its done on twitter bootstrap:
Follow #twbootstrap
I notice they use a lot of attributes prefixed with 'data-'. So what's the right way?
Well..
I believe going with the "data-" attributes would be best, since its a nice little nifty feature of HTML5.
Also, it'll keep your markup clean.
So if you think your application would be running on Modern browsers, this should be the way to go.
I'm new to CRM2011 and can, but I have been given a task that I don't know how to solve and didn't find any answers in Google.
I've 2 entities. Case and Notes (Annotation - system entity). Notes is related to the case and represented by area on a form where users can add their notes. After a new note has been added I need to run a JS. How can I do it? I can not assign onchange event, because it's system entity and I can't modify anything there, even choose OnChange Event. I can't set event handler on a case form for this note. Properties blocked as well. If I send event handler onchange area where s not property embedded.
Does anyone know how to run JS on a change of related system property to the form?
Thank you
I believe that, depending on the exact details of your task at hand, you might want to use a plugin instead. The downside is that you won't be using JavaScript but C# (if you haven't build a plugin before you're in for a treat). The upside is that you won't be using JavaScript but C#.
You might want to intercept the messages of Create on the entity Note or the message of Update on the entity Case.
Could you, please, elaborate on what is the goal?
*I was wondering if i could do all these in javascript, as opposed to having rails helpers
In my application, there are several types of "if-else" UI cases. This is a fairly common scenario, and i wonder if anyone has a tidy way to do these?
EG 1) There might be several types of links with the same behavior: "upvote", etc.
If it is the user's own article, i do not want it to be passed to the server, but pop up a dialog box
EG 2) There might be a several links called "follow", "become a fan", etc
If the user already have done the given action before, it should be a text "followed" instead of a link.
Normally you'd use helpers for this. You write helpers called, based on your examples, upvote_button (which might take a user as a parameter) or follow_button (where this one might take true/false for already-following/not-following.
If you can be more specific as to what you need, I can probably be more specific in my answer.