keystone-classic: [v0.3] Boolean fields with noedit:false and hidden:true do not retain value
Expected behavior
If a hidden yet editable boolean field has a true
value in the database, it should retain it when it’s saved through the admin UI.
Actual behavior
The field will always be set to false
, even if it were true
before
Steps to reproduce the behavior
1/ Add a Boolean field to a list
completed: {
type: Boolean,
default: false,
noedit: false,
hidden: true
}
2/ add a pre(‘save’) hook that will set it to true
if it’s not:
keystone.list('MyList').schema.pre('save', function(done){
if(!this.completed){
console.log('SETTING IT TO TRUE');
this.completed = true;
}
done();
});
Re-saving the document in the admin UI will output 'SETTING IT TO TRUE'
every time.
Motivation
This is useful for allowing documents that are constructed over time. I have several lists that allow people to come back and modify the document until a certain condition is met in which case further modification should no longer be allowed.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16 (12 by maintainers)
Commits related to this issue
- Add e2e testing to demonstrate issue #2946 — committed to keystonejs/keystone-classic by jstockwin 8 years ago
- Ensuring hidden Boolean fields persist correctly, fixes #2946 — committed to keystonejs/keystone-classic by JedWatson 8 years ago
Since the Admin UI is all react talking to an API we can submit a value now - it’s not a problem (for us) anymore. 0.3 actually submits an HTML
<form>
.Legacy use of the UpdateHandler would break with the change I’m proposing but we can work out a way around that. I’ll open another issue for discussion when I’m ready.
The
hidden
option wasn’t really intended for security, as such… but you’re right, it doesn’t mean others may not use it as one 😃Given our focus on 0.4 and that whatever the fix is won’t come forward anyway, I’m just going to hack a fix for this (for boolean fields specifically) into 0.3 now