[Repeat Group] Validation with Ajax (jQuery) + php

premierhw

Member
Hello again Folks,

I need a script which validate the input value's existence in the database.
If the value exist then return as '1(one)', if not return '0(zero)' by query in php.

These input fields are with Repeat Group and I actually use validation with Fabrik backend however it does not always work so I need to create own validation for it.

I firstly created the script to own js file using 'wildcard(id^=...)' but it only worked first row but not after 2nd row :

Code:
$(document).on('blur','[id^=join___28___test_81_repeat___element_]', function(e){
        $.ajax({
        type: "POST",
        url: "./index.php?option=com_custom&format=raw",
        data: "code="+$("[id^=join___28___test_81_repeat___element_]").val(),
            success: function(result){
                if(result == 0){
                    alert('This value is not exist in the DB');
                }
            }
        });
    });

So next, I created 'form_x.js' file to components > com_fabrik > js folder and created the code as below:

Code:
Fabrik.addEvent('fabrik.form.group.duplicate.end', function(form, event){
    var groupId = 81;
    var repeatMax = form.repeatGroupMarkers[groupId];
    var code = form.formElements['join___28___test_81_repeat___element_'+(repeatMax-1)].getValue();
 
    $.ajax({
    type: "POST",
    url: "./index.php?option=com_custom&format=raw",
    data: "code="+code,
        success: function(result){
            if(result == 0){
                alert('This value is not exist in the DB.');
            }
        }
    });
});

I am aware Joomla and Fabrik use Mootools but is there any possibility if I can use jQuery Ajax? (I usually use jQuery in my website and I use 'jQuery(document).ready(function($) {' for avoiding conflict...)

Could anyone can help this problem, I would really appreciate.
Thank you in advance.
 
Hehe, I found the solution :)
This works fine.

Code:
Fabrik.addEvent('fabrik.form.group.duplicate.end', function(form, event){
    var groupId = 81;
    var repeatMax = form.repeatGroupMarkers[groupId];
    var code = form.formElements['join___28___test_81_repeat___element_'+(repeatMax-1)].getValue();
 
    var request = new Request({
        url: "./index.php?option=com_custom&format=raw",
        method: 'post',
        onSuccess: function(result){
            if(result==0) {
                alert('This value is not exist in the DB.');
            }
        }
    })
    request.send('code='+code);
});

I swap jQuery ajax to Mootools ajax.

Refer those links:
http://fabrikar.com/forums/index.php?threads/autofill-does-not-work-with-my-site.26930
http://stackoverflow.com/questions/13414502/function-mootools-ajax-to-post-date-to-form

But how can I use 'Blur' event instead of 'fabrik.form.group.duplicate.end'?
If I cannot use 'blur' then How can I use this script From element with Javascript plugin?

Thank you in advance.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top