• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Composer custom field validation

Scheduled Pinned Locked Moved Plugin Development
composer
14 Posts 2 Posters 875 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Sebastián CisnerosS Offline
    Sebastián CisnerosS Offline
    Sebastián Cisneros Gamers
    wrote on last edited by
    #1

    I already created a custom field in the composer, and is working perfect. Now I want to add some validation, just like the one nodebb core has when you try to publish a topic without a title and you get this alert.

    4d34ca5d-cfff-4afc-ad98-ce85a25e074c-image.png

    How can trigger this same alert with a different message and avoid the composer to submit (until this field validates)?

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #2

    Use 'filter:composer.check'

    hooks.on('filter:composer.check', function (payload) {
         payload.error = 'sorry you can not post now';
         return payload;
    });
    
    Sebastián CisnerosS 1 Reply Last reply
    1
  • Sebastián CisnerosS Offline
    Sebastián CisnerosS Offline
    Sebastián Cisneros Gamers
    replied to <baris> on last edited by
    #3

    @baris Is this hook still working? I remeber I used this last year, but now for some reason I dont know the hook is not firing.

    barisB 1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    replied to Sebastián Cisneros on last edited by
    #4

    @Sebastián-Cisneros Should still work how are you listening to it?

    Sebastián CisnerosS 1 Reply Last reply
    0
  • Sebastián CisnerosS Offline
    Sebastián CisnerosS Offline
    Sebastián Cisneros Gamers
    replied to <baris> on last edited by
    #5

    @baris here is some of my code, all hooks are firing, all but the "filter:composer.check"

    (function(config, app, ajaxify, $, templates) {
        'use strict';
    
        
    
        $(document).ready(function() {
    
    	
            require(['hooks'], function (hooks) {
    
    
               //validation of composer data before submit
                hooks.on('filter:composer.check', function (payload) {
    
                    console.log('------------- HOOK NOT FIRED -------------')
    
                    
                });
    
                //on composer open load variables to tpl
                hooks.on('filter:composer.create', function (data) {
    
                    console.log('------------- HOOK FIRED -------------')
                    
                });
            });
    
            //fired after composer is loaded, and ready for javascript
            $(window).on('action:composer.loaded', function (ev, data) {
    
                console.log('------------- HOOK FIRED -------------')
                
            });
    
            // after composer submit
            $(window).on('action:composer.submit', function(ev, data) {
                
                console.log('------------- HOOK FIRED -------------')
                
            });
    
            //after composer edited, we re load the tags of the post detail page if needed
            $(window).on('action:posts.edited', function(ev, data) {
    
                console.log('------------- HOOK FIRED -------------')
                
            });
    
            //after composer posted new
            $(window).on('action:posts.loaded', function(ev, data) {
    
                console.log('------------- HOOK FIRED -------------')
    
            });
        
        });
    
    })(config, app, ajaxify, $, window.templates || null);
    
    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #6

    Did you try putting a console.log here to see if it's triggered?

    Sebastián CisnerosS 1 Reply Last reply
    0
  • Sebastián CisnerosS Offline
    Sebastián CisnerosS Offline
    Sebastián Cisneros Gamers
    replied to <baris> on last edited by Sebastián Cisneros
    #7

    @baris yes, and the console log is working there. So Its like the fire event is not reaching my function or something.

    I actually modified that composer file in that place, and added my code there and its working. But this is not a clean solution, I should be able to do the same with the hook.

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #8

    @Sebastián-Cisneros said in Composer custom field validation:

    //validation of composer data before submit
            hooks.on('filter:composer.check', function (payload) {
    
                console.log('------------- HOOK NOT FIRED -------------')
    
                
            });
    

    Did you check if this code is executed? You should be able to look in the hooks module loaded property to see if your listener is added.

    Sebastián CisnerosS 1 Reply Last reply
    0
  • Sebastián CisnerosS Offline
    Sebastián CisnerosS Offline
    Sebastián Cisneros Gamers
    replied to <baris> on last edited by
    #9

    @baris said in Composer custom field validation:

    console.log('------------- HOOK NOT FIRED -------------')

    console.log('------------- HOOK NOT FIRED -------------')
    is not being logged

    how can I look into the hooks module properties?
    console log of the hooks var? when?

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #10

    Like this

    console.log('adding hook listener');
    hooks.on('filter:composer.check', function (payload) {
                console.log('------------- HOOK NOT FIRED -------------')
    });
    console.log(hooks.loaded);
    

    See if those print the function you just added.

    Sebastián CisnerosS 1 Reply Last reply
    0
  • Sebastián CisnerosS Offline
    Sebastián CisnerosS Offline
    Sebastián Cisneros Gamers
    replied to <baris> on last edited by
    #11

    @baris said in Composer custom field validation:

    console.log(hooks.loaded);

    {
        "action:ajaxify.start": {},
        "action:ajaxify.end": {},
        "filter:composer.check": {},
        "filter:composer.create": {},
        "filter:notifications.load": {}
    }
    

    337a9fac-aca5-417e-b83a-8ae14540fa5c-image.png

    Sebastián CisnerosS 1 Reply Last reply
    0
  • Sebastián CisnerosS Offline
    Sebastián CisnerosS Offline
    Sebastián Cisneros Gamers
    replied to Sebastián Cisneros on last edited by
    #12

    @Sebastián-Cisneros

    this is how I have the current hook coded

    //validation of composer data before submit
                hooks.on('filter:composer.check', function (payload) {
    
                    console.log('filter:composer.check');
    
                    var selectedTags = [$(".composer #topic-list-select").val()];
    
                    console.log('selectedTags');
                    console.log(selectedTags);
    
                  
    
                    return payload;
                    
                });
    

    nothing is getting logged on the console after submitting the composer.

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #13

    Maybe put a breakpoint here and check why your listener isn't triggered. I tried on this forum and it worked fine.

    Sebastián CisnerosS 1 Reply Last reply
    0
  • Sebastián CisnerosS Offline
    Sebastián CisnerosS Offline
    Sebastián Cisneros Gamers
    replied to <baris> on last edited by
    #14

    @baris Thanks for the help. I appreciate it.

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development