Keyword

required fields not taken into account

More
10 years 6 months ago #127062 by tex14
Hi

I make extra fields required.
But if I submit an item in front-end, I have no alert (like to choose category ) and item is saved even if extra fields are empty.

Did I forgot to check another option somewhere ?

thanks for advice

Please Log in or Create an account to join the conversation.

More
10 years 6 months ago #127063 by Lefteris
Replied by Lefteris on topic Re: required fields not taken into account
Hi. Probably you have an override of itemform.php which is missing the required code. You can always view the default code at the file components/com_k2/templates/default/itemform.php.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
10 years 6 months ago - 10 years 5 months ago #127064 by tex14
Replied by tex14 on topic Re: required fields not taken into account
k2 v2.6.8.

sorry it's not this solution.
I put the original file in the template (override works for other pages), cleared server cache, cleared browser cache, but no validation.
anyway validation never worked before override.


edit:
in fact I see that validateExtraFields function is in file"media/k2/assets/js/k2.js".
and this file is not loaded, just "components/com_k2/js/k2.js" is loaded and which is not the same javascript.

so I added : $document->addScript(JURI::root(true).'/media/k2/assets/js/k2.js');
in plugins/system/k2/k2.php
so k2.js (with fonction) is loaded but validation still doesn't work.

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago #127065 by Lefteris
Replied by Lefteris on topic Re: required fields not taken into account
I cannot verify the issue. I just tested under Joomla! 3.2 in front-end and i got the message for extra fields that are required. Check your page for javascript errors. Also the file media/k2/assets/js/k2.js should be loaded automatically, i don't know why it's not loaded for you.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago - 10 years 5 months ago #127066 by tex14
Replied by tex14 on topic Re: required fields not taken into account
So I put some alert box in k2.js to test with my 3 empty extra fields.

the result is :
bbbbb
k2 trim = false
k2 hassclass = false
<p> = false
TRUE
response = true

where is the problem ???
thanks for advice
// Extra fields validation
function validateExtraFields() {
        $K2('.k2Required').removeClass('k2Invalid');
        $K2('#tabExtraFields a').removeClass('k2Invalid');
        var response = new Object();
        var efResults = [];
        response.isValid = true;
        response.errorFields = new Array();
        $K2('.k2Required').each(function() {
                var id = $K2(this).attr('id');
                var value;
                if ($K2(this).hasClass('k2ExtraFieldEditor')) {
                        if ( typeof tinymce != 'undefined') {
                                var value = tinyMCE.get(id).getContent();
                                        alert('aaaaa');
                        }
                } else {
                        var value = $K2(this).val();
                        alert('bbbbb');
                }
                if (($K2.trim(value) === '') || ($K2(this).hasClass('k2ExtraFieldEditor') && $K2.trim(value) === '<p></p>')) {
                        alert('ccccc');
                        $K2(this).addClass('k2Invalid');
                        response.isValid = false;
                        var label = $K2('label[for="' + id + '"]').text();
                        response.errorFields.push(label);
                }else{
                        alert('k2 trim = ' + ($K2.trim(value)===""));
                        alert('k2 hassclass = '+$K2(this).hasClass("k2ExtraFieldEditor"));
                        alert('<p> = ' + ($K2.trim(value) === "<p></p>"));
        
                }
        });
        $K2.each(response.errorFields, function(key, value) {
                efResults.push('<li>' + value + '</li>');
        });
        if(response.isValid === false) {
        alert(' FALSE');
                $K2('#k2ExtraFieldsMissing').html(efResults);
                $K2('#k2ExtraFieldsValidationResults').css('display','block');
                $K2('#tabExtraFields a').addClass('k2Invalid');
        }else{
        alert('TRUE');
        }
        alert('response = ' +(response.isValid));
        return response.isValid;
        
}

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago #127067 by Lefteris
Replied by Lefteris on topic Re: required fields not taken into account
Revert back all the changes. I suggest to install K2 again from getk2.org/assets/get . The ensure that there is an element with ID k2ExtraFieldsValidationResults in your page. If not then probably you have an override and you have to update it. An other thing to do is to check your browser console for errors.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago - 10 years 5 months ago #127068 by tex14
Replied by tex14 on topic Re: required fields not taken into account
No javascript error with the console and same problem with a template without override.


K2 v2.6.9 (Developer Build) installed.
same problem : no extra fields validation

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago #127069 by Lefteris
Replied by Lefteris on topic Re: required fields not taken into account
Which browser are you using? Are the extra fields set as required ?

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago - 10 years 5 months ago #127070 by tex14
Replied by tex14 on topic Re: required fields not taken into account
Which browser are you using?
firefox , chrome

Are the extra fields set as required ?
yes. and I checked in the database too.

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago #127071 by Lefteris
Replied by Lefteris on topic Re: required fields not taken into account
Is the title validation working? The itemform.php file that is used should be looking like this github.com/joomlaworks/k2/blob/master/components/com_k2/templates/default/itemform.php while the javascript file should be looking like this github.com/joomlaworks/k2/blob/master/media/k2/assets/js/k2.js. An other thing to do is check for any third-party K2 plugins installed in your system and try to disable them.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum