5 Replies Latest reply on Aug 9, 2011 1:00 PM by George_Johnson

    'Field.prototype.newProperty'  possible?

    MarkWalsh Level 4

      I'd like to add some properties to fields (TextFields, CheckBoxes, etc.) in a form to keep track of certain states/conditions for them, and I thought I was able to do this long ago using the 'prototype' for the field. I may be mistaken as I haven't found anything I have coded that used that, nor have I found any reference online to using a Field's prototype. It's possible that I had been able to use the prototype for a different object instead of a Field, but I vaguely remember needing to do this for a Field, and being quite happy that I had found a solution for what I was trying to do.

       

      Is this another senile moment for me, or is it possible to do what I want?

        • 1. Re: 'Field.prototype.newProperty'  possible?
          George_Johnson MVP & Adobe Community Professional

          Do these properties you want to add need to persist after the document is saved and reopened?

          • 2. Re: 'Field.prototype.newProperty'  possible?
            MarkWalsh Level 4

            Not necessarily (this is a pet project, and I haven't decided on all of the parameters on how I want it to work just yet), but depending on the circumstances, that might be a good thing if it is possible. If it's not possible, it wouldn't be a big deal to reset these properties when the document is reopened if that becomes necessary.

            • 3. Re: 'Field.prototype.newProperty'  possible?
              George_Johnson MVP & Adobe Community Professional

              Once you get a field object into a variable using getField, you can add properties to it dynamically, but they will only survive as long as the variable that references the field object. So there's no need to use the prototype.

               

              If you need it to persist, you can co-opt the little used "submitName" field property to store as much text as you need. You can use a delimiter character (e.g., | (pipe)) to separate values if you want multiple values, and later parse them out using the split string method. You will only run into a problem if the form is set up to submit using HTML format.

              • 4. Re: 'Field.prototype.newProperty'  possible?
                MarkWalsh Level 4

                Actually, what I'm trying to do is replace my current 'SubmitName' workarounds with something more robust and user(me)-friendly.

                 

                 

                So, if I create a variable, 'oField', and I give it it's own custom property (how to do this?), I can access that property whenever I want, as long as 'oField' is still in scope?

                 

                ...But, that also means, that I would have to create a separate variable for each field which I need to store this info for? If I'm substituting one slightly complicated workaround for another, then I probably won't persue this any further. I wanted to make this as simple as possible, especially when rushed changes need to be made to the form. Creating variables each time a field is added/removed is just too much overhead for what I was envisioning. I was just certain that I had come across a way to do this long ago.

                • 5. Re: 'Field.prototype.newProperty'  possible?
                  George_Johnson MVP & Adobe Community Professional

                  For example:

                   

                  // Get a field object
                  var oField = getField("text1");
                  
                  // Add a custom property
                  oField.bogus = "some value";
                  
                  

                   

                  But yes, it will only be available as long as oField is. This is probably more complicated than using the submitName property.

                   

                  Using the field prototype may have worked a while ago, but it doesn't appear as though you have access to it now.