jqgrid error message on delete - jqgrid

I've added the following code for my jqgrid:
changeTextFormat = function (data) {
return "Activity or one from the same price group already used";
};
jQuery.extend(jQuery.jgrid.edit, {errorTextFormat: changeTextFormat }
)
It works great for insert and I get the error message appearing in the top of the dialog.
However I want something similiar for deletes. I want to make it that if during my server side delete I find a problem with the operation I throw an exception.
Based on this exception I want to pop up an error message.
Can anybody tell me how to go about this for the delete function?

The setting $.jgrid.edit is not the only setting which are used during form editing. There are also $.jgrid.del, $.jgrid.nav, $.jgrid.search and $.jgrid.view which can be used.
If you need to define default implementation of errorTextFormat callback you can use
$.extend($.jgrid.del, { errorTextFormat: changeTextFormat });
in the same way like you use it with $.jgrid.edit.

Related

Fullcalendar Problems w/ filtering Events in agendaDay-View (works only one time, then no more events exist)

I have a problem with filtering events:
I use fullcalender in agendaDay-View
I use a drop-Down list to select a driver
I compare the name (it is a property of event-object) with the selected value
(this part is ok)
Then,
I remove all Events (.fullCalendar('removeEvents');)
Add the specific events
(add with renderEvents doesn't work proberly at the moment)
And now my problem appears:
For the first time it works, however, when I select another 'driver', the events are gone, because of the 'removeEvents'-Action before.
So, how can I solve this problem, that I can only display the filtered events and keep the other (actualley all events) to filter again for second, third n- time?
$('#' + id).fullCalendar('refetchEvents');
was the first idea, however, its brings all back and selected Issues were doubled (and so on).
I'm thankful for every hint.
Ok I think you can solve your problem with fullCalendar's eventRender function.
The function can also return false to completely cancel the rendering of the event.
Your event from events.json should have a property like 'driver_id'.
I would have select field instead of dropdown with option keys being driver ids, values - names or whatever. Lets say it's id would be 'driver_select'.
Then render events like this:
$('#calendar').fullCalendar({
//...
eventRender: function(event, element) {
//driver select should have default value assigned or else no events will be rendered
if ($("#driver_select").val() !== event.driver_id) {
return false; //do not render other driver events
}
}
//...
});
Handle select changes to update
$("#driver_select").off('change').on('change', function() {
$("#calendar").fullCalendar( 'refetchEvents' );
});
Another approach would be to show all drivers in a timeline. For that you can use FullCalendar Scheduler.

how to show error message for textfield validation based on server response

I have a textfield which has to be validated based on the user input.By validate what I mean is, I need to check if the name exists in the database and if it exists display error message accordingly.
How I am doing this is, I have a change listener for the text box, within the listener I have a ajax request which connects to a java action and check if name already exists in db, and sends back a response. On ajax success, I am trying to set error message... But the error message is not being set..
{
fieldLabel : 'Company Name:',
xtype : 'textfield',
required: true,
allowBlank : false,
name : 'companyName',
msgTarget: 'side',
listeners : {
change : function(th,n,o) {
console.log("change-EV");
/*****ajax request here****/
this.markInvalid('N.V..!');
// this.setActiveError('NV..',false);
},
blur: function(th){
console.log("Blur-ev");
}
}
}
Is the approach I am using right? Will I be able to achieve this with ajax request?
If you are using change event of textfield it will get fired for every letter typed
If you use blur then it will get fired when you move to other element
as per my understanding of your problem in your case you should use blur event
as blur fired make a ajax call for check and if country name exists throw the exception from server side, it will fail the ajax call
so you can show the error message in ajax failure callback
I suppose that you are trying to make Ajax call for every letter typed,
Is that right ? because this might be a lot of overhead on the server. Can we use a combobox with list of names in the the store bound to the combobox, then filter based on the type ahead just filter the values from the store using store.filterBy().

Using autocomplete on a form not in DOM

Let me begin by saying that I'm on JQuery version 1.3.2. Upgrading at this point is not an option.
I have a form that is added in by a templating system after the page load occurs. I'm very new to JQuery but it's my understanding that live will allow me to access it.
The function for the autocomplete already serves a user search and works well. I want to share this function for the admin part of the site as well as the query is almost identically the same.
The clientName element is from the dynamically added form. If I use the code below, nothing happens; no data is retrieved.
$('#clientName')
.site_clientAutocomplete(
'admin',
function( $event, $result, $data )
{
$('#clientName').val($data.ClientName);
}
);
If I wrap it inside the following code, it will work, sort of. I have to click inside the input box several times before I can get anything back from the database.
$("#clientName").live('keydown', function(){
});
Can someone tell me how I can get this autocomplete to function properly?
live is just for handling events that occur on elements matching the selector now or in the future. If you need more robust detection of elements matching your selector, you can either apply the widget when the content is added, or you can use the livequery plugin
With livequery, you can "listen" for new elements matching your selector and run a function when that event occurs. In your case, this would go something like this:
$('clientName').livequery(function () {
$('#clientName').site_clientAutocomplete(
'admin',
function( $event, $result, $data )
{
$('#clientName').val($data.ClientName);
}
);
});

ajax form validation with PHP

I am using PHP Zend framework and jQuery ajax to submit and validate a form using json data format. The PHP works great, the ajax works great too. The only problem is that if the form has more than one invalid input (e.g name and email are both invalid), the ajax executes error:function() part.
Here is the ajax code:
.ajax({
type:'POST',
url:'processForm.php',
dataType:'json',
data:str,
success:function(data){
//do something when ajax call is complete
//setup variables
switch (data.internal_code){
case 0:
$('#NameError').html(data.msg0);
break;
case 1:
$('#EmailError').html(data.msg1);
break;
case 2:
$('#TextError').html(data.msg2);
break;
case 3:
$('#contactForm').fadeOut(2000);
$('#successMessage').fadeIn(2000);
$('#successMessage').fadeOut(4000);
break;
}
},
error:function(data){
alert ("ajax did not work");
}
Please let me know how I can fix this error.
you need to look at what is in the error callback and determine what's going on. Or alternatively, open up webkit inspector or firebug and look at what is coming back from the server.
If your request works for valid input or input with 1 error, and you get the error callback for 2 invalid inputs, I bet the server is crashing and returning a 500. Without looking at the response from your server, its impossible to help more.
You cannot use a switch statement to check multiple forms because the outcome is only one set of actions.
The normal way to do it is to explicitly encode your JSON on the server to give a more meaningful result:
if(data.internal_code_0){
// do something
error++;
};
if(data.internal_code_1){
// do something else
error++;
};
// then at the end of the field processing
if(error == 0) {
// reset form field states and button states
// no need to submit form again - it has already been done!
};
You see here I am using explicit data.internal_code_0 it actually doesn't matter what value it contains, rather that it is either set or not, and therefore I can deal with multiple errors on the client side using ìfs.
Also I count the number of errors so that at the end of processing I know if all the fields have passed muster or not.
On the PHP side do this
if(!isset($_POST['inputFieldHTMLName']))
{
// do something
}
else
{
$errors['internal_code_0'] = 'you forgot to enter a value ';
};
// ... check other fields
if (count($errors, 1)>0)
{
echo json_encode($errors);
}
else
{
// form is good. Continue with processing
};

jQuery Execute Order

I'm using the following jQuery plugin and it executes when there's a click action on the specified element :
http://www.andresvidal.com/labs/relcopy.html
I also created a click function for the same element, but I expected it to execute after the plugin. However that isn't the case, the click function always executes first, thus causing problems.
Please check my code below for example, I'm new to jQuery so any suggestions / help would really be appreciated!
$.getScript('../js/relCopy.js', function() {
$('#AddTable').relCopy({
limit: 10,
excludeSelector: '.newListSelected'
});
$('#AddTable').click(function() {
do something here after relcopy has finished
});
Event handlers are executed in the order they were bound, and since the callback from $.getScript() executes after that script is loaded, it's binding it's click handler after yours.
So get the order you want you need to bind in the order you want, that means binding your click handler in the callback as well, like this:
$.getScript('../js/relCopy.js', function() {
$('#AddTable').relCopy({
limit: 10,
excludeSelector: '.newListSelected'
}).click(function() {
//do something here after relcopy has finished
});
});

Resources