Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI to allow user to delete/clear a field value #391

Open
rickpasetto opened this issue Sep 27, 2022 · 14 comments
Open

Add UI to allow user to delete/clear a field value #391

rickpasetto opened this issue Sep 27, 2022 · 14 comments
Labels
enhancement New feature or request

Comments

@rickpasetto
Copy link

Generated from #390

When editing a row in a collection, it would be great to be able to clear a field, especially an enum field specified by enumValues. Doing so would remove the field from storage of that entity. If the field is required, it should generate an error. Otherwise, it should be allowed to remove a field that's been set.

Hope this is enough information. Thanks @fgatti675 for encouraging filing an Issue.

@fgatti675 fgatti675 added enhancement New feature or request 2.0.0 labels Sep 28, 2022
@Andre3424
Copy link

@fgatti675 great, this would be very useful, because now we must edit changes in firestore.
By when will 2.0.0 be ready? :-)

@fgatti675
Copy link
Member

Added the clearable prop to string, number and date properties in the latest version :)

@rickpasetto
Copy link
Author

rickpasetto commented Oct 6, 2022

@fgatti675 that's great! Thank you. So, now, if I set:

clearable: true

on a property, it should be able to be cleared? What does the UI look like for that?

(Sorry if this is a naive question; I'd done a

yarn add @camberi/firecms@next 

and it pulled down version 2.0.0-alpha.34, and I added the above clearable flag, but I don't see any difference in the UI (i.e. I don't see a "clear" icon on my properties). What might I be doing wrong?)

@fgatti675
Copy link
Member

Hi, it simply adds a clear icon at the end of the input field, setting the value to null

@fgatti675 fgatti675 reopened this Oct 7, 2022
@fgatti675
Copy link
Member

Can you check if it work in the latest version? :)
2.0.0-alpha.35
I think there was a css issue

@rickpasetto
Copy link
Author

Hi @fgatti675 . I just downloaded 2.0.0-alpha.37 and I still do not see a clear icon on a property that has enumValues (sorry). Other than adding the clearable: true flag, is there anything I am missing?

@fgatti675
Copy link
Member

So we need to add it in multiple field bindings, it might be right in some of them but wrong in others, can you share your exact configuration?
In the demo you can see a working example for name and category
https://demo.firecms.co/c/ppp/B000P0MDMS

@rickpasetto
Copy link
Author

@fgatti675 Thank you so much for helping with this! I see that example working. I think this might be my misunderstanding about the feature. What I want to be able to do is edit an existing field to clear it. In other words, a user wants to delete a value that's already stored in the database, not clear one as they are entering a new entity (although that's a good feature too). So, in the Collection view, I want to be able to hover over a field (that's clearable) and click on "X" to clear it. Make sense?

Here's a code snippet, in case it helps:

const types = buildEnumValues({
  "First": "first",
  "Second": "second",
  "Third": "third"
});
const styles = buildEnumValues({
  "title": "title",
  "body": "body",
  "caption": "caption"
})

const resourceMediaCollection = buildCollection({
  path: resourceMediaPath,
  alias: "resourceMedia",
  name: "Resource Media",
  icon: "Portrait", // https://mui.com/material-ui/material-icons/
  singularName: "Media Resource",
  properties: {
    type: {
      name: "Type",
      validation: { required: false },
      clearable: true,
      dataType: "string",
      enumValues: types
    },
    line1copy: {
      name: "Line 1",
      columnWidth: 350,
      description: "Line 1 Copy Format",
      dataType: "string",
      validation: { required: false },
    },
    line1fontStyle: {
      name: "Line 1 Font style",
      defaultValue: "title",
      validation: { required: false },
      clearable: true,
      dataType: "string",
      enumValues: styles
    },
    thumbnail: {
      name: "Thumbnail",
      validation: { required: false },
      clearable: true,
      dataType: "string",
      storage: {
          storagePath: "thumbnails",
          acceptedFiles: ["image/*"],
      }
    },
    mediaFiles: { 
      name: "Resource Media",
      dataType: "array",
      of: {
        dataType: "string",
        storage: {
          storagePath: "resourceMedia",
          acceptedFiles: ["image/*", "video/mp4"],
        }
      }
    },
  }
})

@fgatti675
Copy link
Member

fgatti675 commented Oct 10, 2022

Hi @rickpasetto
So having a clear button when a cell is selected in the collection view, that sets the value to null would work for you?

@rickpasetto
Copy link
Author

Yes, I think so. Something like this?
Screen Shot 2022-10-10 at 7 49 13 AM

@Andre3424
Copy link

@fgatti675 Just read the conversation above and we are looking for the same.
So, lets day the category, which is "Cameras" in the screenshot above is optional. The user can select a category or none.
Lets assume the user has selected "Cameras". Now he decides to remove the category, this is not possible now.

@rickpasetto
Copy link
Author

@fgatti675 just checking in on this issue. Do you need any more information from me?

@rickpasetto
Copy link
Author

rickpasetto commented Dec 7, 2022

@fgatti675 I notice that you answered my original question. I just tried version 2.0.0-alpha.48, but I still am not able to clear a row like shown above (after adding the clearable: true property to the field). To be clear, I need to be able to do it for an existing entity.
Could I be doing something wrong?

@rickpasetto
Copy link
Author

@fgatti675 any progress on this issue? I'm still unable to clear a field of an existing row.

@fgatti675 fgatti675 removed the 2.0.0 label May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants