I want the html.checkbox() in ASP.NET MVC to be as a link that goes to an action controller (GET and not POST).
Question:
It is possible to make the html.checkbox() to act as a "actionlink" instead of going to the FormCollection without using Javascript and JQuery or any additional plugin?
This wouldn't be possible in any framework as checkboxes are just static input elements. They have no ability to trigger any sort of action on their own, hence where javascript and event handlers comes in.
You could try making a form who's method is GET, but it would still have to go somewhere.. I guess you could make an action that handles various states of a checkbox and then routes to the correct page, however you'd still need to submit this form by having the user click a submit (again because the only way to trigger an action from clicking a checkbox is by using javascript)
You could also fake a checkbox using css and checkbox-like images.
text goes here
If you need to show it as either checked or unchecked, you would use two classes with two different checkbox-like images.
I doubt this is possible without javascript.
Except for buttons and links, no controls actually do anything but change their own value in the DOM.
It would however be rather trivial to add an onclick to your checkbox that would do whatever (including a GET request).
Related
I'm somewhat new to rails and am wrapping a GUI around a CLI tool to give some non-technical users some self-service. Part of the tool contains a page where the user selects a few values from some drop downs etc, and then clicks one of a few buttons on the screen to kick off their desired actions. The fields where they make their selections are outside of the forms that the buttons belong to. On button click, I want to call a javascript function that will grab the values the user selected, and post an ajax call back to the server to run the command corresponding to the button, and then when the request returns I want to insert the command output into a text area.
The only problem I'm having is with getting the values of the fields outside of the form generated by button to, and including them in the ajax request. Outside of rails this is pretty trivial, but I'm having a hard time getting this to work. Does anybody have any suggestions or examples?
Thanks
There's really no need for what I was trying to do... it ends up I can just use the form_tag helper and multiple submit_tag helpers to create the submit buttons with different values. See this post for details: How do I create multiple submit buttons for the same form in Rails?
Also, here is a great write up on the javascript portion (it uses coffee script, but I didn't have any trouble following it even though I'm using jquery): http://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html
I have a simple scaffold and I want the user to see (preview) the form data before he submits it. It looks to be fairly straight forward problem but surprisingly I am not able to figure out how to do it. I found this but it looks to be somewhat dated (2010 question)
Is there any gem or jquery plugin which can simplify this preview functionality ? any suggestions on how to do it in rails 3.2.x ?
Thanks
It really depends on what kind of "preview" you want to include - either "preview page" or "rendered fragment":
Preview page is what some services are showing: summary of all inputs shown in form of separate page with button "confirm". It doesn't require javascript or anything fancy - just click "next" on form page, see data typed just a second ago and click "confirm" or "back to edit". If this is what you require then you can do it simply by creating new controller action(preview?) which would initialize model with passed parameters(just like "create" action would, but without saving) and generate template with "preview" shown and hidden form that will be passed to "create" action after clicking "confirm". Alternatively you can simply modify "new" form so it would hide form depending on called action and show preview instead.
Second option is "render fragment" - it will live-update part of your current page via javascript. Depending on how complicated this view will be and what kind of operations you will need to do before showing template it might be good to use some javascript plugin or send request to server and obtain rendered partial. In former case you can select from very easy implementations(like this) up to complete solutions dedicated to it. On the other hand if you choose to render it on server then simple ajax request with all params of form should be enough to provide you with HTML output that can be put directly into DOM element.
I don't know about any gem which can do that.
I think showing a modal with jquery and getting data from data-elements is a simple way to go.
If you've used the Magento admin, then you know that when you tab between the "Shipping Address" order screen it's kind of buggy. It does an AJAX call behind the scenes anytime that any field is updated. This keeps the shipping up to date, but its very annoying when trying to key in orders. Does anyone know a good way to disable this automatic functionality, so that it could be done with a button, instead of happen "automagically"?
I can't point to anything specific at the code level, as I don't have the code handy to look at just now, but I know it won't be easy per-se.
You will need to find and rewrite (unless it's all in the templates, then you'll need a custom admin theme) the block which generates that form, strip out the calls which add the handlers to the onblur events. Theoretically, your button should be able to call the same JavaScript method which is called via the onblur of the form elements.
Newbie here, scratching my head on this one.
How do you normally save information specified in a popup dialog for use by other forms on your page?
Scenaro:
Click an options button, which pops up a dialog.
Set some checkboxes, radio buttons, etc...
Submit form (dialog seems to need it's own form)
Do you usually just save the inputs in a session, cookie, or do you have another way access your dialog controls from the main form?
Seems like I'm missing something basic, as it should be easy to set some options and use them on the rest of the page.
All advice appreciated!
If you are trying to pass data from one page/dialog to another see Passing parameters between pages
I have an address search area on my form in my asp.net mvc3 application. the whole form is submitted using the main submit button and the address search is initiated using the search button.
When the user submits the form using the search button only the house number and postcode fields need to be validated. When the user submits the whole form the whole form needs to be validated.
How is this achieved using fluentvalidation?
This is not an ideal situation in MVC design but still you can achieve this buy submitting form on search button click by jQuery. Use separate identifier to specify whether it was submitted by search button or main button by passing additional parameter through jQuery either in model itself or querystring. Once you have that identifier on serverside, you can use custom fluentValidation to validate model with that if..else condition. You can use .ajax as well if that fits in your design.
Hope this helps.