cancel
Showing results for 
Search instead for 
Did you mean: 

Share Action Form with Hidden Fields

eamell
Champ in-the-making
Champ in-the-making
I have an Alfresco server side action and I have a Share action associated with it.  There are 4 parameters to the action; 2 required and 2 optional.  Instead of showing the fields and letting the user enter them I am doing a database query and displaying a table that will allow the user to select a row.  I have a custom control that renders the table and one of the two required fields.  I then have hidden fields for the other three fields.  The selection of the row works fine and populates the values of the hidden fields correctly.  However the submit (OK) button doesn't get enabled.  After digging for a while I have found that no events are triggered when the value of the hidden field is set in JavaScript.

I don't consider myself a JavaScript programmer and was sort of hoping there was an easy solution.

The following is how I am setting the value of the fields (the method is called each time … localThis is used to work around scoping rules in object oriented JavaScript):

<javascript>
    function setHiddenFieldValue(fieldName, fieldValue) {
        var field = YAHOO.util.Dom.get(localThis.fieldNamePrefix + fieldName);
        field.value = fieldValue;
    }
</javascript>

The following is a sanitized version of my form from my share custom config:


    <config evaluator="string-compare" condition="fn-create-some-folder">
        <forms>
            <form>
                <field-visibility>
                    <show id="someNumber" />
                    <show id="someType" />
                    <show id="someName" />
                    <show id="someTypeDesc" />
                </field-visibility>
                <appearance>
                    <field id="someNumber" label-id="label.create-some.available_some_list">
                        <control template="/org/alfresco/components/form/controls/createSomething.ftl">
                            <control-param name="parentNodeRef">{node.nodeRef}</control-param>
                        </control>
                    </field>
                    <field id="someType">
                        <control template="/org/alfresco/components/form/controls/hiddenFieldWithId.ftl" />
                    </field>
                    <field id="someName">
                        <control template="/org/alfresco/components/form/controls/hiddenFieldWithId.ftl" />
                    </field>
                    <field id="someTypeDesc">
                        <control template="/org/alfresco/components/form/controls/hiddenFieldWithId.ftl" />
                    </field>
                </appearance>
            </form>
        </forms>
    </config>


hiddenFieldWithId.ftl is nearly identical to hidden.ftl except that I actually set the ID of the hidden field to make it easier to get.
4 REPLIES 4

zladuric
Champ on-the-rise
Champ on-the-rise
Hi,

So you need to trigger the event? You could fire a desired event from JS, like
YAHOO.Bubbling.fire('eventName')
.

But you can also try firing the form validation manually. You can use the

eamell
Champ in-the-making
Champ in-the-making
Doesn't <javascript>YAHOO.Bubbling.fire()</javascript> fire system wide events rather than control specific events?

You also didn't finish your sentence on firing the form validation manually; although I found a way I would be interested in knowing other ways.

Thanks!

eamell
Champ in-the-making
Champ in-the-making
Just for completeness I was able to find my own solution.  It was really quite simple (which I figured it would be).  YUI has an event simulator, which is limited for YUI 2.x but still offers what I needed.

First of all there are 2 events that trigger validation on the form: propertychange and keyup.  Property change would probably make the most sense but I didn't find a way to trigger that so I am working with keyup.  YUI 2.x offers the class YAHOO.util.UserAction which allows some user actions to be simulated; in this case there is a method keyup which simulates the keyup event on the object sent to it.  So I changed my JavaScript function as follows:

<javascript>
    function setHiddenFieldValue(fieldName, fieldValue) {
        var field = YAHOO.util.Dom.get(localThis.fieldNamePrefix + fieldName);
        field.value = fieldValue;
        YAHOO.util.UserAction.keyup(field);
    }
</javascript>

This didn't work at first because <javascript>YAHOO.util.UserAction</javascript> wasn't available so I added the following to my custom config:


    <config>
       <dependencies>
          <js src="yui/event-simulate/event-simulate.js" />
          <js src="components/com/microstrat/something/createSomething.js" />
       </dependencies>
    </config>


The second script reference was already there and contains my
setHiddenFieldValue()
method (as well as other code).  The only thing I don't like is that the event-simulate.js is included rather than conditionally including event-simulate.js or event-simulate-min.js depending on the value of debug.

zladuric
Champ on-the-rise
Champ on-the-rise
Basically I was going to say about the keyup event, but the answer ran away Smiley Happy