Not able to make fields readonly in edit mode
Hi Jinzhu and team. Awesome product to make the life of go developers easy especially which came from python/Django background. I'm stuck while trying to make some of my model fields read-only i.e. once saved, the fields should not be allowed for editing. Please help or suggest any other way.
Configuring the meta type as read-only does not work for you?
Than you might have to work with custom Setter to ignore the updates. https://doc.getqor.com/admin/fields.html
Type as read-only won't help me because my use case is once a user enters a value and save, it should become un-editable. I have gone through the whole doc but not able to find any specific custom type, could you please share some sample code snippet.
Search for virtual field in the link I posted. There you will find this code for passwords.
user.Meta(&admin.Meta{Name: "Password",
Type: "password",
Valuer: func(interface{}, *qor.Context) interface{} { return "" },
Setter: func(record interface{}, metaValue *resource.MetaValue, context *qor.Context) {
if newPassword := utils.ToString(metaValue.Value); newPassword != "" {
bcryptPassword, _ := bcrypt.GenerateFromPassword([]byte(newPassword), bcrypt.DefaultCost)
record.(*models.User).EncryptedPassword = string(bcryptPassword)
}
},
})
for your application, I'd just check if the value was previously saved and discard any changes. This won't make it disabled in the HTML, though.