# Required image

**URL:** <https://forum.wixstudio.com/t/required-image/6453>\
**Category:** Ask the community\
**Tags:** wix-forms, code, question\
**Created:** [July 22, 2018, 4:04pm UTC](https://forum.wixstudio.com/t/required-image/6453 "2018-07-22T16:04:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![blairamirez8](https://avatars.discourse-cdn.com/v4/letter/b/67e7ee/32.png) [@blairamirez8](https://forum.wixstudio.com/u/blairamirez8)\
**Post date:** [July 22, 2018, 4:04pm UTC](https://forum.wixstudio.com/t/required-image/6453/1 "2018-07-22T16:04:45Z")

</div>

Hey!

I have some forms that ask for an image to be submited. I said the image input is mandatory, but is not turning red if you are not uploading an image, so the users get confused.

What should I do?

Thank you!

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [July 23, 2018, 9:04am UTC](https://forum.wixstudio.com/t/required-image/6453/2 "2018-07-23T09:04:52Z")

</div>

Using the example code from the API, you can display a message to the user that they need to select a file:

```javascript
export function button1_click(event, $w) {
    if ($w("#uploadButton1").value.length > 0) {
        $w("#text1").text = `Uploading ${$w("#uploadButton1").value[0].name}`;
        $w("#uploadButton1").startUpload()
            .then((uploadedFile) => {
                $w("#text1").text = "Upload successful";
                $w("#image1").src = uploadedFile.url;
            })
            .catch((uploadError) => {
                $w("#text1").text = "File upload error";
                console.log(`Error: ${uploadError.errorCode}`);
                console.log(uploadError.errorDescription);
            });
    } else {
        // display msg to user that no file was selected
        $w("#text1").text = "Please choose a file to upload.";
    }
}

```

---

<div class="post-metadata">

**Author:** ![blairamirez8](https://avatars.discourse-cdn.com/v4/letter/b/67e7ee/32.png) [@blairamirez8](https://forum.wixstudio.com/u/blairamirez8)\
**Post date:** [July 23, 2018, 2:11pm UTC](https://forum.wixstudio.com/t/required-image/6453/3 "2018-07-23T14:11:42Z")

</div>

Hey! thank you for answering. I tried that but then, everytime they want to update their profile they have to upload an image, eventhough they uploaded one before…

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [July 24, 2018, 4:43am UTC](https://forum.wixstudio.com/t/required-image/6453/4 "2018-07-24T04:43:03Z")

</div>

So if they’ve already uploaded, you can make it optional:  
**$w(“#uploadButton”).required = false;**

You can also skip the upload in the button1\_onClickI() and change or eliminate the message to be displayed in the **Text** field.

---

<div class="post-metadata">

**Author:** ![blairamirez8](https://avatars.discourse-cdn.com/v4/letter/b/67e7ee/32.png) [@blairamirez8](https://forum.wixstudio.com/u/blairamirez8)\
**Post date:** [July 24, 2018, 10:40am UTC](https://forum.wixstudio.com/t/required-image/6453/5 "2018-07-24T10:40:20Z")

</div>

Thanks Yisrael! At the end I did this and its working!

$w.onReady( function () {  
$w(‘#dynamicDataset’).onBeforeSave(() =\> {  
if (!($w(‘#input16’).valid) && $w(“#uploadButton1”).value.length \> 0) {

let validationMessage = ‘’;

if (!$w(‘#input16’).valid)  
validationMessage += ‘Please enter the profile image and all the required information\n’;

```
        $w('#validationMessages').text = validationMessage; 
        $w('#validationMessages').expand(); 
    } 

```

**else**  
$w(‘#validationMessages’).collapse();

```
}); 

```

});

I created another question on the forum, I wonder if you could help me that well there too… :)))

> **[Velo by Wix: Full-Stack Web Dev | Build Professional Web Apps](https://community.wix.com/velo/forum/coding-with-velo/create-or-generate-a-unique-id-for-every-submit)**
>
> Ask questions, get answers from the community and stay up-to-date with new features.

Thank you very much!!!
