ajax,validation,grails , Grails command object validation with Ajax


Grails command object validation with Ajax

Question:

Tag: ajax,validation,grails

In a Grails project I have a command object to validate submitted forms. This command obj. also has custom validators. The data is submitted with jQuery ajax ($.post).

My question is how can I now map the data send with jQuery Ajax to the properties listed in the Command object?

For example:

$.post('comment/save', {id: id, title: title});

and then in the controller:

def save(saveCommand cmd){

  if (!cmd.validate()){
    ...
  }
}

class saveCommand {

   Comment comment_id    // maps to: params.comment_id send with ajax
   String title          // maps to: params.title send with ajax

   // constraints
   // validators    
}

Answer:

The comment_id attribute should be bound from a "comment_id" parameter in the parameter map you sent from jQuery, not as "id" as you have right now.

Anyway, I guess you have a Comment domain class, and you expect to bind this entity from database. In this case, you should add a ".id" suffix to your parameter name.

$.post('comment/save', {"comment_id.id": id, "title": title});

PS: maybe you want to rename the "comment_id" to "comment" in your command class. Doing that, you will have to change the parameter name in your ajax request as "comment.id".


Related:


ajax test not working


javascript,php,jquery,ajax
I tried to get a simple ajax-test working but without success. I am trying to pass a variable($add1) from PHP to JS, then let the JS calculate the sum and return it back to a PHP variable via $_POST and ECHO it out in the html. index.php: <?php echo "<script...

how to multiply two column names using codeigniter validation rule


php,codeigniter,validation
I have three columns.The product of two columns get into third column name income_amount using codeigniter validation rule.the first column is crop_quantity and the second is per_rate controller $this->form_validation->set_rules('crop_quantity', 'Crop Quantity', 'required|numeric'); $this->form_validation->set_rules('per_rate', 'Per Rate', 'required|numeric|callback_get_product'); $this->form_validation->set_rules('income_amount', 'Income Amount', 'required|numeric');...

how to use geocoder class to retrieve latitude and longitude through ajax


javascript,ajax,google-maps
the json array which contains the list of addresses [ { "id": 0, "title": "Coop.Sociale Prassi e Ricerca Onlus", "latitude": 0, "longitude": 0, "address": "Viale Eleonora D'Arborea 12, Roma, IT" }, { "id": 0, "title": "San Lorenzo", "latitude": 0, "longitude": 0, "address": "Viale della Primavera 330, Roma, IT" },...

How to use ajax response JSON data?


javascript,jquery,ajax,json
I have made my ajax request, which works great and returns JSON. But how do i use it? My response is something like this [{ "id": "5", "reviewID": "2389", "serviceID": "50707", "title": "well done" }] Now in my success function I am trying to use the data like such: success:...

jquery - add header request to specific ajax request


javascript,jquery,ajax
I need to add some header details to one specific ajax request that one of the third party control will make. The third party control allows me to set the URL but it does not allow me to add header information to the request. So far I am able to...

How to validate non-db attributes on an ActiveRecord model?


ruby-on-rails,validation,activerecord
I have the following class: class Instance < ActiveRecord::Base attr_accessor :resolution validates_format_of :resolution, with: /\A\d+x{1}\d+\d/ def resolution=(res) validate! (set the resolution etc) end def resolution (get the resolution and return) end end The resolution attribute is not stored in the database, but is a transient property of the instance. When...

file input type not being included in jquery FormData for AJAX send


javascript,php,jquery,ajax
I have a simple form that will be sent via AJAX to a php file for processing, this form includes a file upload, for some reason the file upload is not being included in the data to be sent. My html form: <form id="business-form"> <label for="business-name">Business Name:</label> <input type="text" id="business-name"...

How to trigger ajax loading with an observable varariable in knockout?


ajax,knockout.js
I got some tabs in a page. When clicking on a tab, the currentTab changes its value, which should trigger an ajax loading of a new tab content. The concept is similar to a ko.computed, which however, only update another variable as the value change takes place. Is there any...

How to return value in Meteor.JS from HTTP.call “GET”


javascript,ajax,http,meteor,facebook-javascript-sdk
I'm writing a meteor method, which should return a Facebook response for HTTP.call on graph api, but HTTP.call has only a callback function to show error/response, so I can't take this data outside, and Method can not return any value. Here's my method code: loadUserFBEvents: function () { var accessToken...

How to transform $.post to $.ajax?


javascript,jquery,ajax,json,servlets
I have this $.post peace of code: $.post("../admin-login", { dataName:JSON.stringify({ username:uname, password:pass, }) }, function(data,status){ console.log("Data:"+data); answer = data; } ); and I wont to transform it to $.ajax. On the servlet side I am demanding request.getParamter("dataName") but I do not know how to write data: section in $.ajax so...

WooCommerce seems to only orderby date and not price


php,ajax,wordpress,woocommerce
I am loading in variable products via a custom WP_Query $args = array( 'post_type' => 'product', 'posts_per_page' => 100, 'product_cat' => 'beast-balls', 'orderby' => 'date', 'order' => 'desc' ); $loop = new WP_Query( $args ); if ( $loop->have_posts() ) { while ( $loop->have_posts() ) : $loop->the_post(); ?> <div class="product-node cat-beast-balls">...

access the json encoded object returned by php in jquery


php,jquery,ajax,json
I want to post some data to php function by ajax, then get the encoded json object that the php function will return, then I want to get the information (keys and values) from this object, but I don't know how, here is my code: $.ajax({ url: "functions.php", dataType: "JSON",...

Modal won't close on ajax success


jquery,ajax
I'm loading in the content of a modal with ajax. I have a button that submits the modal form and is suppose to close the modal when it's done processing the ajax submit so it can update a table at the bottom of the page. It's not closing the modal...

Using $.ajaxStop() to determine when page is finished loading in CasperJS


javascript,jquery,ajax,phantomjs,casperjs
So far in my tests written in CasperJS, I've been using waitForSelector() on page-specific elements to determine if a page has fully loaded (including all the async ajax requests). I was hoping to come up with a more standard way of waiting for page load and was wondering if the...

When is the cookie set by AJAX available in javascript?


javascript,ajax,cookies
I'm doing an AJAX call and setting a cookie in the user browser in the response (the server code sets the cookie). I noticed in the success callback from the ajax, the cookie is not available. When I look in document.cookie the new cookie is not there. My question, when...

How to simulate $.ajax array POST request with Java


java,javascript,php,ajax
I'm trying to simulate ajax post request with java program. The simulation works but if I post an array, it comes back as a string. I'm using Guava: Map<String, String> data = new HashMap<String, String>(); data.put(URLEncoder.encode("affected_ids[]", "UTF-8"), URLEncoder.encode(Joiner.on(":").join(arrIds), "UTF-8")); data.put("select_all", "true"); String d = Joiner.on("&").withKeyValueSeparator("=").join(data); The content of d looks...

Automatically calling server side class without


javascript,html,ajax
I have an anchor which calls a server side class when clicked, but I want to modify it so that the class is called as soon as the page loads, without having to click an anchor. <a href="#" class="_repLikeMore" data-id="1234" data-type="pid" data-app="forums"> ...

Loading external php file in a div with jquery ajax


javascript,php,jquery,ajax,mysqli
i am making a simple project..and i need to load data from other page in an index.php..and i have set time of 20sec. but its not working.. could u please tell me what is wrong with the query..Thanks already.. index.php <?php include 'connection.php'; ?> <html> <head> <title> My First Chat...

Run AJAX function on form submit button after javascript confirm() cancel


javascript,jquery,ajax,wordpress,forms
I have a form where and AJAX function runs on form submission to make sure that the data in the form doesn't conflict with data in the database. If a conflict is found, the AJAX function pops up a confirm() box. If the user clicks "OK", the form is submitted....

Check with jquery if result/echo from PHP starts with “abc”


php,jquery,ajax
I am using jquery and ajax to submit forms without page reloading and then depending on the result (whether it is a success or an error) I print the message in two different divs. Since success and error in ajax only checks the client/server connection I echo some stuff from...

jQuery validate equalTo


javascript,jquery,validation
I would like to use jQuery validate() plugin using the equalTo to validate a signature field, basically the signature field must match the first name and last name field, is this possible using the validate() plugin? http://jqueryvalidation.org/equalTo-method/ shows me how to check if it is equal to another input, but...

Parameters from f:param not submitted with AJAX request when form enctype is multipart/form-data


ajax,jsf,jsf-2,jsf-2.2,wildfly
I'm running Wildfly 8.2 and I'm using the JSF version bundled with it, 2.2.8-jbossorg-1. I have the following facelet: <h:form enctype="multipart/form-data"> <h:commandButton value="Submit"> <f:param name="myparam" value="true"/> <f:ajax execute="@this" render="@this"/> </h:commandButton> </h:form> When I press the submit button, several parameters are submitted, but not myparam. If I remove enctype="multipart/form-data" from the...

Making an alert() with PHP and ajax


javascript,php,jquery,ajax
I have an ajax function that submits some data to my PHP file. In my PHP file I have some checks that it does with that data, I then try to make an alert to come up to say something. I can't get any alerts to come up though. All...

How use jquery getJSON with a local variable


javascript,jquery,ajax,json,ace-editor
i want to extend the completions of Ace Editor, and i need a json of word, this is my code: function load_completions() { var object = $('#preview').attr('class'); $.ajax({ type: "POST", url: "test_editor_ajax.php", data: {action:'load_completion', object:object}, cache: false, success: function(json){ var adminCompleter = { getCompletions: function(editor, session, pos, prefix, callback) {...

Correct PHP contact form syntax? [duplicate]


php,forms,validation
This question already has an answer here: PHP: “Notice: Undefined variable” and “Notice: Undefined index” 11 answers I am trying to follow a PHP contact form tutorial from here! Seems pretty simple and I'm completely new to PHP. However, when running my project, I get so many "Notice" messages...

Why are fields reset after ajax update with Primefaces


ajax,jsf-2,primefaces
On a form I have some personal information (name, address etc.) and a changeListener which updates the salutation and letter salutation according to the gender and last name. If the underlying entity was already stored in the database it works fine. If I'm entering data for a new (not saved)...

cross domain ajax form post — How is this allowed?


jquery,ajax
I am using jQuery and jQuery form plugin There is a method in jQuery form plugin ajaxSubmit. You pass a form and then it submits it via ajax and you get a response. I am wondering how this is possible since the form is on a different server than the...

Very weird behavior when using “var” keyword in an ajax request


javascript,ajax,variables,var
I've been worrying about this for a while and I can't realize what's really happening. Explanation in code comments. There are 2 versions of an application, one of them throws weird results and the second one does the expected work. var id = "test1"; $.post("http://fiddle.jshell.net/echo/json/", {"data": "data"}, function(a) { alert(id);...

Validation of a form before submission


php,validation,symfony2,form-submit
Using Symfony, version 2.3 and more recent, I want the user to click on a link to go to the edition page of an already existing entity and that the form which is displayed to be already validated, with each error associated to its corresponding field, i.e. I want the...

How to dynamically add a row without “Requested unknown parameter” error


javascript,jquery,ajax,datatables
I am new to DataTables and I am having problems in dynamically adding a new row to the datatable. Here is my initialization: table = $("#college-list").DataTable({ 'ajax': { 'url': 'admin/get_college', 'type': 'GET' }, 'columns': [ { 'data': 'college_abbrev', "bSortable": true }, { 'data': 'college_name' , "bSortable": true }, { "mData":...

json_encode and parsing information if there are no records returned


php,ajax,json
I make some AJAX (PHP + JQuery), but I have one problem. I have: dataType:"json", in Javascript Everything works fine when json_encode returning some records from DB. The problem is what to do, how to say server in case that there are not any records? When I have an array...

Getting a collection via Ajax to show in view


jquery,ruby-on-rails,ajax
All I'm trying to do is have a collection populate in the view when a user clicks a button. But I feel like I'm making this way too complicated and it's not working. See my code - where am I going wrong? Click handler: $('#filterrific_results').find('.followup-injury').on('click', function(e){ e.preventDefault(); $.ajax({ url: "/assessments/followups",...

Identifier starts immediately after numeric literal


jquery,ajax,razor
I'm trying to get the current logged in usersID in my jquery function var userID = @User.Identity.GetUserId(); Many answers on this page say that I have to do something like \"@User.Identity.GetUserId()\" But it dont seem to work, can someone tell me how to fix it. Its for my ajax post....

How to send current page number in Ajax request


javascript,jquery,ajax,spring-mvc,datatables
I am using jQuery DataTable to display huge amount of data in a table. I am getting data page wise on Ajax request like this: var pageNo = 1; $('#propertyTable').dataTable( { "processing": true, "serverSide": true, "ajax": "${contextPath}/admin/getNextPageData/"+pageNo+"/"+10, "columns": [ { "data": "propertyId" }, { "data": "propertyname" }, { "data": "propertyType"...

Multiple AJAX forms with the same ID on the same page


javascript,php,jquery,ajax,forms
I have two AJAX newsletter subscribe forms on the same page (top and bottom). Both forms have the same ID. The top form works perfectly, however I'm unable to get the alert messages to appear in the bottom form. I found this question but wasn't sure how to implement the...

Disable 2 buttons after click of a button


javascript,php,jquery,html,ajax
I have a submit button on page index.php When i click this button another script (call.php) is called through ajax that holds some response. Now i want that time between the click of submit button and response displayed/received under a div through the call of ajax script the buttons option1...

No Ajax success after php-script is run


php,jquery,ajax
I have a php-script which performs a database backup of my website. This backup-script can be triggered by clicking a button on the websites' admin-panel. I'd like to have some text in the admin-panel that tells the user when the backup is ongoing and when it's complete (process takes about...

How to write .htaccess file for AJAX page


php,jquery,ajax,.htaccess
I am working on a website which i am going to develop as a CMS. So i am writing .htaccess file. page link and url working fine, but when i performing ajax request then i am getting 404 error for the url. I am placing my .htaccess file code and...

Javascript/jQuery form validation


javascript,jquery,forms,validation
I got most of this form validation to work properly but the only issue is that when the form detects an error on submit and the user corrects the mistake, the error text won't go away. This can be confusing for the user but I can't seem to figure out...

Unable to upload file to Sharepoint @ Office 365 via REST


javascript,ajax,rest,sharepoint,office365
I'm having trouble creating/uploading files via Microsoft's REST API (or at least that's what they call it) for Sharepoint running on Office 365. It looks like I'm able to authenticate all right, but I'm getting 403 Forbidden when I try to create a file. The same user can upload a...

Jquery parsley validate not working


javascript,php,jquery,ajax,parsley.js
if($("#dataform").parsley().isValid()){ $.ajax({ url : '<?php echo base_url();?>index.php/company/final_review?id=<?php echo $this->input->get('id'); ?>', type : 'POST', data : $("#dataform").serialize(), dataType:"json", beforeSend: function(){ $('#remarks').parsley( 'addConstraint', { minlength: 5 }); }, success : function(data){ console.log(data); } }); } This is my ajax part. The plugin is not validating the field it's submitting the form. The...

Is there a way to fire an event every time an ajax call in made in AngularJS?


javascript,ajax,angularjs,express
What I'm trying to do is every time a call to the backend is made, I want a spinner to load up with a dark overlay. I know I can do this by simply running the spinner before the call is made, but I'm working with multiple developers and I...

Codeigniter Form Validation Rule for match (password)


php,forms,codeigniter,validation
I am trying to write Form validation rules in my Controller to submit Change Password form in which I am checking the old password too. I am getting the old password(current) from db and placing it in a hidden input field. My Rules are simple and are given below $config=array(...

Check AJAX response data before taking action


javascript,php,jquery,ajax
I have an AJAX call to a PHP script that returns either the content of a Bootstrap3 modal, or an HTML form. PHP code - (ajax.php): if ($numLegs == 1) { echo $formData; } else { echo $modalContent; } If it returns $formData, I want to display the form data,...

.NET wep api won't accept %2E or . in api request uri


c#,jquery,asp.net,ajax,json
We're trying to create our first web api using the .net framework. To try this we've used this demo project: http://www.codeproject.com/Articles/549152/Introduction-to-ASP-NET-Web-API In this project we've changed the find() function of the AJAX script so it only sends one var to our new democontroller.: <script> var uri = 'api/Demo'; function find()...

How to load two PHP scripts simultaneously using jQuery?


php,jquery,ajax
I have an upload feature that is made up of various different stages, and the duration of this upload can be quite lengthy. To increase usability of this feature, I want to present the user with information concerning the progress of the upload. The upload is processed through jQuery, and...

Seeding fails validation for nested tables (validates_presence_of)


ruby-on-rails,ruby,validation,ruby-on-rails-4,associations
An Organization model has a 1:many association with a User model. I have the following validation in my User model file: belongs_to :organization validates_presence_of :organization_id, :unless => 'usertype==1' If usertype is 1, it means the user will have no organization associated to it. For a different usertype the presence of...

Sending LIst via ajax to complex model


javascript,c#,asp.net,ajax
I know I've done this before but I can't seem to get this to work. I have the following JavaScript; $("#btnTestVouchers").click(function () { var postData = { "workplaceGiverId": $(".wpgDropdownList").val(), "fromMemberId": $(".wpgFromMemberDropdownList").val(), "toMemberId": $(".wpgToMemberDropdownList").val(), "voucherExpiryDate": $("#expiryDatePicker").val(), "recipients": JSON.stringify("[{'firstname':'a','lastname':'b','email':'c','voucheramount':'d'}]") }; console.log(postData); $.ajax({ type: "POST", url:...

How to calculate values of a drop down menu with PHP/ JS?


javascript,php,ajax
Hi I have been very puzzled how to do this and cannot find any relevant tutorial that could help me so I thought I would ask here and hope to find the help. I have a form with 2 drop down menus, each of them having a value attribute. What...

Storing result from FOR loop as one array (array only saves each results seperately)


javascript,jquery,arrays,ajax
I have tried searching but can't find anything to help, maybe my problem is too simple! Anyway, I'm running an ajax request. The data given to the request is an array. Here is my code: var id = "1#2#3#4#5#"; var chkdId = id.slice(0, -1); var arr = chkdId.split('#'); var checkedId...