Expand my Community achievements bar.

SOLVED

Clear Out ImageField

Avatar

Level 3

I currently have a button that allows a user to add an image to an ImageField...using LCD 8.x

Once the user add an image into the field, there is no way for them to remove it. I therefore need to add a "Remove Image" button.

What would I need to do to clear out the ImageField, which is called myImage?

All suggestions are appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Steve's solution above should work in a static form. It would look like:

xfa.resolveNode("NA-Image-1").rawValue = null;

Not sure what the issue would be with dynamic forms, we have not had problems.

In any case Steve's solution should work for you in either the click event or the mouseUp event of the button.

Niall

View solution in original post

10 Replies

Avatar

Level 10

or:

xfa.host.resetData("xfa.form.EntryForm.Page04-PI-Nature.myImage");

You can add additional fields inbetween the quotation marks separated by an ","

Avatar

Level 3

Hi Steve,

Thank you for the quick feedback...appreciate that.

Your suggestions assumes (I think) that the imageField is the current field and that will most likely not be the case.

If I have a separate button called "Remove Image" I thought I could put some javascript in the mouseUp event that went something like this:

myImage.rawValue = null;

But that does not seem to work. Do I need to refresh the screen or something, after the image is removed?

Avatar

Level 3

Hi Niall,

Interesting that you have ALL the form-related information! lol

Thank you for the suggestion.

I put this JavaScript code into the mouseUp event and I don't get an error, but the images does not disappear either.

Thoughts?

Avatar

Level 10

Hi David,

Save the form as "Dynamic" in the Form Properties and File Save As...

The reason I sugested this route was that you could add the caption field as well. The script is JavaScript, so make sure you have set this as well. It works here...

Niall

Avatar

Level 3

Niall,

The Save-As Dynamic worked. Thank you.

I must say that I'm not comfortable converting my form to a dynamic one. I do remember reading a while ago that there are differences between static and dynamic forms, so I don't want to get "bitten later."

Is there a way of handling this within a static form?

Avatar

Correct answer by
Level 10

Steve's solution above should work in a static form. It would look like:

xfa.resolveNode("NA-Image-1").rawValue = null;

Not sure what the issue would be with dynamic forms, we have not had problems.

In any case Steve's solution should work for you in either the click event or the mouseUp event of the button.

Niall

Avatar

Former Community Member

Hmmm...I successfully tested using both the click and mouseUp events on Button to call the script. My form is static.

How about trying calling 'xfa.layout.relayout()' after you null the ImageField?

Avatar

Level 3

Thank you Niall...this worked great.

Avatar

Level 3

Hi Steve,

The relayout() still didn't work.

I'm wondering if this did not work because of how I was referencing the my field.

As you have seen from my previous post, the following worked.

xfa.resolveNode("NA-Image-1").rawValue = null;

Thank you for your help.