I have a textbox with remote datasource for autocomplete(jquery) [not the plugin, the original one shown in jquery ui demos ]
How do I make sure user typed only what was in one of autocomplete suggestions and nothing of his own ?
The question is lacking specifics, but I will assume you mean validate on the client side since you referred explicitly to the auto complete plugin. This answer will have two parts. The first is the original answer, assuming one autocomplete plugin. The second is revised based on updates to the question.
1) Using http://docs.jquery.com/Plugins/Autocomplete
The best solution for this is the "mustMatch" option. Here is the API documentation.
If set to true, the autocompleter will only allow results that are presented by the backend. Note that illegal values result in an empty input box.
You should be able to use it in this way:
$("selector").autocomplete("url", {"mustMatch": true});
You can also validate the user input in some way in the "result" event. Here is a link: http://docs.jquery.com/Plugins/Autocomplete/result .
2) Using http://jqueryui.com/demos/autocomplete
There is no mustMatch option here. You could extend the plugin, or you could add something similar to what I mentioned for the other autocomplete plugin. Use the "change" event.
$( ".selector" ).autocomplete({
change: function(event, ui) { ... }
});
If you were using an array as a datasource, this would be more efficient. Since you are using a remote data source you would need to do another final query using ui.item to validate the user value. You can then allow or deny the default behavior.
In either case, the input should still be validated in some way on the server side. This is out of the scope of jQuery plugins.
Related
Multiple required fields from bulk edit form are not displayed. The labels for that fields appear on form but the textboxes don't appear. I think this happens because we have scripts that run for that fields. I tried to edit customizations.xml and to put BehaviorInBulkEditForm = "Enabled" but it is not working. Is there another way to enable javascript?
As per the Form XML schema, the BehaviorInBulkEditForm attribute goes on the <event> element, careful you're not putting it somewhere else.
The valid values, as per Microsoft KB 949941, are:
Enabled
If you use this value, the field is enabled. Additionally, the code for the event is run when the event is called.
Disabled
If you use this value, the field is disabled.
EnabledButNoRender
If you use this value, the field is enabled. However, the code for the event is not run when the event is called.
I would recommend to stay away from unsupported customizations which will eventually break in future updates.
If it’s worth, then move all the logic to post-update or pre-update plugins which is fail proof server side implementation rather than client side js route.
In my Symfony 2 application I need to filter input before passing it on to validation [1], however, I can't seem to find any system within Symfony to do this.
The type of filtering I looking for is e.g. to be able to filter a dash out of a specific field before validating it. E.g. users can enter 123-123 but the only accepted value is 123123. Just as I can set up validation rules with constraints, I'm looking for something similar for filters.
[1] http://symfony.com/doc/current/book/validation.html
Nifr's answer is good but is missing of an important alternative that, if I understand correctly your question, seems to fit perfectly your needs.
You can use a hook that is pretty much an event listener: if something happens or is going to happen, it intercepts the event and redirect it to your function.
In this case, you need a PRE_BIND hook (is deprecated since 2.3 version, now it's called PRE_SUBMIT)
Read this if you need help about
Either write your own Validation Assert to filter and then proxy the other validators for this purpose ...
... or one or multiple Regex Asserts.
... or use a DataTransformer to transform/filter the input.
With the DataTransformer involved you could aswell consider creating a new FieldType which renders two inputs with a seperator like the date form-field does. ( if not not used with widget => single_text )
That's the only way I could get it work, both for NavGrid or filterToolbar.
Reloading has no effect from server side , even if I'm sure that the resulting json data is correct.
Am I wrong ?
If you have implemented searching on the server side you don't need to use loadonce: true. Die implementation of Advanced Searching for example consist from analyzing of filters parameter which can be send to the server as the part of request to fill the grid. The format of filters parameter is described here. If you would use stringResult: true parameter of filterToolbar then you will have the same format of input data in both Advanced Searching and Toolbar filtering.
$('submitbutton').addEvent( 'submit', function(e){
e.stop();
$('fuss').send();
req2.send();
});
trying to get this working but not sure if it is possible and had no success so far.
Mootools docs doesnt helped me either.
Will the multiple usage of .send() work?
Do i have to specify the data beeing send for the html request or does it take automatical the data beeing send by the form ?
It's in the documentation: http://mootools.net/docs/core/Request/Request#Element:send
This shorthand method will do a request using the post-processed data from all of the fields.
You can do as many requests in a specific event as you wish, as long as they're all asynchronous.
In your specific example it would seem you want to do two requests using two different methods, one with setting up a new Request class manually and the second doing it via the Element Method.
Based on your last comment, I wrote a little example in jsFiddle.
Basically I think you don't need two request for your goal. Just override onRequest method to update the html.
I have an ajax->autoComplete working dandy with cakePHP. Now I want to add my own javascript (preferably callback methods) after the request has been executed. I know that there are options associated with the ajaxHelper but I cannot figure out for the life of me how to apply them to the autoComplete function.
I can get ajax->autoComplete('div', 'url', array('with'=> 'console.log("hello")')) to execute BEFORE anything happens the very first time, but none of the other options linked to above work (I think because 'with' puts the javascript directly in the address, so obviously it will execute). I have also read the autoComplete API and googled around for a bit, but can't find any examples or documentation of how to apply options.
You are correct, there are AJAX options. And then, there's this:
http://api.cakephp.org/view_source/ajax-helper/#line-129
You can use any of those options in the "options" array.