Expand my Community achievements bar.

Unable to get the value of pathfield on button handler in Multifield

Avatar

Level 4

Hi,

I am trying to get the value of pathfield on button click.


CQ.form.TextPathMultifield = CQ.Ext.extend(CQ.form.CompositeField, {
    /**
    * @private
    * @type CQ.Ext.form.PathField
    */
    linkURL: null,
    
    /**
     * @private
     * @type CQ.Ext.form.Label
     */
    linkText: null,

    /**
     * @private
     * @type CQ.Ext.form.Hidden
     */
    hiddenField: null,


    constructor: function(config) {
        config = config || {};
        var defaults = {
            border: true,
            layout: "form"
        };
        config = CQ.Util.applyDefaults(config, defaults);
        CQ.form.TextPathMultifield.superclass.constructor.call(this, config);
    },

    /**
     * @override
     */
    initComponent: function() {
        var rootPath = this.rootPath,
            editable = this.editable,
            predicate = this.predicate,
            validator = this.validator;


        CQ.form.TextPathMultifield.superclass.initComponent.call(this);

        // Link URL
        this.linkURL = new CQ.form.PathField({
            anchor: "100%",
            allowBlank: false,
            rootPath: rootPath,
            editable: editable,
            predicate: predicate,
            validator: validator,
            id: 'url',
            name:"./url",
            listeners: {
            change: {
                   scope: this,
                fn: this.updateHidden
                },
            dialogclose: {
                scope: this,
                fn: this.updateHidden
                }
            }
        });
        this.add(this.linkURL);

        //this.elemId = Math.random();
        //this.add(this.elemId);

        // Link text
       this.viewButton = new CQ.Ext.Button({
            "text": CQ.I18n.getMessage("View"),
            listeners: {
            click: function(b,e) {

            this.viewDocument();

            }},
            "minWidth": CQ.themes.Dialog.MIN_BUTTON_WIDTH
        });
        this.add(this.viewButton);

        // Hidden field
        this.hiddenField = new CQ.Ext.form.Hidden({
            name: this.name
        });
        this.add(this.hiddenField);

    },

    viewDocument: function() {
        var value = this.getValue();
           alert("hii");
     },

    /**
     * @private
     */
    updateHidden: function() {
        var value = this.getValue();
         this.hiddenField.setValue(value);
    },

    /**
     * Get value
     * @returns {String} Value
     */
    getValue: function() {
        return this.getRawValue();
    },

    /**
     * Get raw value
     * @returns {string} Raw value
     */
    getRawValue: function() {
        if(this.linkURL.getValue()) {
            return this.linkURL.getValue();//+this.delimiter+CQ.Util.eval(this.linkURL.getValue()+'/jcr:content' + '.json')['jcr:title'];
        }
        return "";
    },

    /**
     * Set value
     * @param {String} value Value
     */
    setValue: function(value) {


        if(value) {
            this.linkURL.setValue(value);
        }


        this.hiddenField.setValue(value);
    },


});

CQ.Ext.reg("textpathmultifield", CQ.form.TextPathMultifield);

Please let me know where I am wrong and the correct way to get the pathfield value.

Thank you

Sumit

0 Replies