This is a migrated thread and some comments may be shown as answers.

JavaScript Correction for GridAttachmentColumn Online Example

1 Answer 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 22 Feb 2011, 05:30 PM
Hi,

I'm not sure where else to submit this so I figure I'd place it here.

There appears to be a minor omission in the JavaScript for the GridAttachmentColumn online example. Visit the example here.

Examine the conditionalPostback function: 

function conditionalPostback(sender, eventArgs)
{
    //The variable 'theRegexp' is never used
    var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
    var eventArgument = eventArgs.get_eventArgument();
      
    if (eventArgument.indexOf("Update") > -1 || eventArgument.indexOf("PerformInsert") > -1)
    {
        if (upload && upload.getFileInputs()[0].value != "")
        {
            eventArgs.set_enableAjax(false);
        }
    }
}

Draw your attention to the variable named theRegexp which appears to be a Regular Expression container. The variable is defined, but it is never used. I suspect that it was supposed to have been used in the If block that follows, like this:

if (eventArgs.get_eventTarget().match(theRegexp)){
    //Disable AJAX functionality
}

...such that the final block actually reads like this:

function conditionalPostback(sender, eventArgs)
{
    //This is the corrected version 
    var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
    var eventArgument = eventArgs.get_eventArgument(); //this variable may not be needed either
      
    if (eventArgument.match(theRegexp)) //or eventArgs.get_eventTarget().match(theRegexp)
    {
        if (upload && upload.getFileInputs()[0].value != "")
        {
            eventArgs.set_enableAjax(false);
        }
    }
}

While the code that was there before would work too, it can prove to be a little confusing for people who aren't terribly familiar with JavaScript who would include that variable definition for no good reason.

Cheers,
John

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 23 Feb 2011, 02:48 PM
Hello Jonathan,

Thanks for reporting this. The unused piece of code is removed and the site will be updated soon.

Veli
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or