There are lots of similar questions to this on SO but none of them have really provided an answer to my particular case. Or at least I can't figure it out!
I have a form with an autocomplete field which is used to populate other fields if a record exists.
I have found that some users type in a value and click to the next cell using the mouse and therefore do not make a selection from the autocomplete list. It's possible that they have typed a value with a matching record in the input field and in that case I want the form to be populated with the appropriate data. Or if it doesn't, then clear the form.
The only way I can think of to check the value exists in the database is to use the change event to make an ajax call to retrieve the data but that doesn't seem like a very elegant solution and I'd be very surprised if there isn't a better way to do this since it seems to me that this would be a very common scenario...
Is there a way to retain the autocomplete array and check it against the input value in the change event? Or how else can I do it?
What you can do is stash away a copy of the data returned in the ajax call's success callback.
You can then add a blur event handler to the autocomplete input, so it'll be called whenever the user clicks away to the next field. In the event handler, check the stashed ajax data, and if there was only a single possible match, use that to populate the input.
I'm trying to add new field in SugarFields and i have many problems. I have to create a new field which is combination of relate field and multienum, when user clicks to select one/many item(s) the list will be loaded to dropdown list (multiselect). I have copied and modified relate field but i can't see how to get data from pop-up window
Have anyone tried this before? Please give me a clue. I'm using SugarCE-6.5.13
Thank you.
I can't upload image so this is a link from mediafire :(
http://www.mediafire.com/view/523c1kwewld18hn#
You do not need to create a custom field. What you actually want to do is add some custom JavaScript that will make an ajax call to the server to obtain the values for the multi-select from the relate.
There are two different types of data for a relate field. Data when you type ahead and data that is returned from a popup.
For the popup: you will need to override the function set_return(popup_reply_data)
I can't remember off the top of my head, how to handle the type ahead.
In an MVC4 project, I have a form that contains a partial view which is an index view of languages studied at school. It is a default type view template index, with Add, Delete, Edit links per row etc. When you Add or Edit, it opens an Add or Edit view for a Language. After e.g. adding a language, the updated partial view is returned.
My problem is that if the user opens the Language form, edits and captures on the main form will be lost. I can't just do an Ajax save before opening the Language form, as the main form may only be partially complete and fail validation. What I am thinking of doing though is using an AjaxPreserve action that takes a FormCollection, and stores it in session (o on disk, or anywhere) and therefore no model binding and server validation is performed.
I then have two problems: I will need to disable client validation before calling the AJAX action, and I will need to repopulate the main form using the FormCollection I saved earlier. I think there should surly be some jQuery voodoo to disable client validation, but I am completely stumped on repopulating the form.
ALTERNATE SOLUTION: Instead of using 'sub-forms', I can use editor templates, in pop-ip forms, where the FK IDs are not required, but that us only in certain cases, so my question still stands.
Could you use something like Knockout where you create javascript model and bind it to a grid/dialog edit/template view. I would transform the whole data to a JS model, bind it to a table/grid and then track all changes on the client side. When all is done, just serialize the whole model back to the server and update the data store.
If this is an acceptable scenario, it will save you a lot of trouble.
Familiarity with Knockout is required, but if you've used it before, you will be able to solve this in a very clean and efficient way.
This example on the Knockout website gives an idea of what I'm trying to suggest. Editing, deleting, adding is done on the client side until you send all of the data back to the server. You will need to track flags for each object to know if it's added, edited or deleted.
http://knockoutjs.com/examples/contactsEditor.html
Simple make the sub request for adding language using Ajax and repopulate the dropdown or what ever way you are accepting language on the main form on sucessfully save.
*This will save a lot of effort. *
Why don't you just use javascript?
E.g. You have main form, that stores some data. And when you need to add something specific like languages you open popup using partial view, allow user to fill form, but when user press submit you intercept action with js, save stuff to javascript array/object or whatever else and maybe store it in a hidden field of main form - for final submit
var newData = new Object();
newData.Field1 = $("#yourField1");
...
lanuageData.push(newData);
$("#languageContainer").val(JSON.stringify(languageData));
...
DataAnnotation validation works here as well like:
$.validator.unobtrusive.parse("your_partial_view_container");
When you need to edit some object that was already added to js array - open popup and fill it up with element of you js array. So basically you do all CRUD on client-side, saving changes only on final submit.
To make your code in a conrolller more clear you can use custom model binder which deserialize some string field from JSon to List or any other kind of object -> so it can be validated on server side.
Would saving your values to local storage be acceptable? What about using TempData?
I have a requirement to ask a question when a certain scenario happens on my MVC 4 view.
When that scenario is true, I simply want to have a jQuery UI dialog pop up modally. That dialog will simply have two radio buttons for "WidgetType" (Purple or Blue).
The viewModel has a property for SelectedWidgetType (that has a default value).
I simple am looking for the best way to handle updating the underlying model with the selection a user picks in the dialog.
Thanks in advance for any replies.
NOTE: I am using this overly simple example as the basis for other dialogs that will have more fields on them that also update the underlying model.
Creating the dialog isn't the hard part, but I am struggling with getting the values.
User jQuery's AJAX post method.
Create a view model JavaScript object on the front end that maps to the parameters of your data model. This view model object can be triggered to get updated each time the user changes his selected options by calling an update method via the change event handles of each form element.
Pass it back to the server controller by packing it into a JSON object using json2.js
If you want a full framework/elegant solution look at using knockout.js which simulates most of this for you... !
I have two Listboxes (select_tag) containing values and I would to create a button that transfer a value from one to the other.
I would like the user to be able to click on one value or more and move them to the other list.
Only then a submit button will send it to the server.
any idea how should I implement it ?
What component/action should I use ?
any design tip or reference that will help me google further will be welcome.
check this website
http://elegantcode.com/2009/07/01/jquery-playing-with-select-dropdownlistcombobox/
basically using jQuery it's the simplest solution.
get element by it's ID or css
get selected value by selector
get other element
add value to the new list by appending html code to existing