Event for all Controls (Textbox) - textbox

I have many textboxes in my form and all of it have keypress.
Is there another way to shorten by code instead writing the code for each texboxes?
Thank You for your Answer.

You can create a subclass (let's call it subTB) of TextBox in which you define the action for keyPressed. Then make your TextBox be instances of subTB instead of instances of TextBox. You have a link to a tutorial in this comment.
Or you can create a function that contains the action to perform when a key is pressed. And the in all your textBox, on the key pressed event, call this function. This second choice will make you also write multiple time the same but this same code will just be a call to the function.

Related

How to have one button do both "enable" and "disable" in ASP.net MVC

I am new to ASP.Net MVC, and still trying to wrap my head around the controller and passing data to the view and back.
Here is my question. I have a model in my view with a property that is "isEnabled", which can be true or false.
I have an edit button, and an enable/disable button. Edit just takes me to a new view with a form.
I want the enable/disable button to change the property of the model to enabled or disabled.
Right now I have two separate buttons. When I click on them, it fires the appropriate action from the controller (EnableModel, DisableModel), and just reloads the current view.
How can I make it so, if the model is disabled the button shows and fires the enable action, and when it is enabled, the button shows and fires the disable action.
So here are the options I thought of.
1. Two buttons, I hide them as needed. I can use an if statement to check if the model is showing or not in razor.
2. Use javascript two to the above
3. Use javascript to physically change the button
What would be the best method?
Alright so looking back can't believe I ever even asked this haha.
I went the javascript route. I had a single button, and a simple onClick javascript class that would handle the toggling.

JSF/Primefaces/PrettyFaces - do action everytime button or link is being clicked

What shall I implement to do certain action whenever button/link is clicked?
I want to save every URL of the page that button is clicked to make a history of pages.
Well,
I come up with following idea: implement custom Navigator with forward & redirect methods which will put pretty faces IDs to history stack. Call navigator's method when using link, call navigator's method in regular beans, so every method's signature will be void.

Rails form select from two options with a button - custom form implementation

I have a website where I want users to be able to select what type of user they are during the registration process.
Specifically, the implementation I want is to have two buttons on the signup page, one called "Seller" and one called "Buyer".
The user should be able to select only one button and once clicked, it should stay highlighted (I know this is just jquery so not the issue).
The selection should be stored in a column in my users model called :type.
It seems pretty straightforward, but the "f.select" form method seems to only implement a dropdown menu, so I am wondering how I can achieve this implementation of two buttons.
Since you're already going to use jQuery, you could add a hidden field for type, create 2 links and style them as buttons, and use jQuery to update the value of type when a user clicks one of the "buttons".

I have a form where i want to add more input fields on button click in MVC View without scripting

I am a newbie, i am trying to create a view where every time i click on add more link next to a Textbox, another text box appears. How do i do that? I searched the same question on this site but i could not find a solution.
You'll have to create an array (string[] Smth)in your model. Then you have to make your "add more" link to submit your form to controller action that will add another element to this array and roundtrip back to view.
You may take a look at the following article which illustrates how you could handle dynamic rows.

Add dynamically an FormItem to a DynamicForm with SmartGWT

I would like to add a FormItem to a DynamicForm in a SmartGWT form, but all I can find is the setItems method, which adds all FormItem of the form, so it can only be used to initialize the form. Am I missing something?
My form contains a TextItem, and each time the user enters a new string and validate, a new CheckButton is added.
Best approach depends on what you want to do:
Dynamically shown item? Add it to the form at initialization, but hidden, then show() it later
repeating form, like the built-in FilterBuilder component? Just add a series of DynamicForms to a Layout, consider tying them together with a ValuesManager
something else? Consider either #2 above, or, setItems() can be used as a means of providing just one new item to the form, just provide a new Array of FormItems including the items you already have. The form will automatically preserve the item's current values.

Resources