-
Notifications
You must be signed in to change notification settings - Fork 237
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
Kit should allow array values to be 'set' instead of overwriting entire array #693
Comments
I'm fairly sure this is a bug, since we introduced support for nested values here: If we support nested values, I would expect to be able to overwrite one without losing any others previously stored. |
As reported in #693 the session data can get overwritten. This happened if there is an array in the session data as the logic takes this to be checkboxes data and stores it, overwriting the existing data.
@daviddotto I've raised a PR to address this issue: #709. Could you check if this fixes your problem? |
Hi @daviddotto just reopening this as the fix has not been released - just checking, did @hannalaakso 's code fix it for you? |
Sorry, yes it did, I hadn't realised I neglected to reply! I needed up rolling my own solution but this solves the original problem |
Having investigated, I think this may be more of a feature request than a bug (which is fine). When we receive object notation:
This is converted to an object in Express (via the qs library):
and then receive an update later on:
becomes
we merge the two objects to get the expected result:
However when we receive array notation, the situation is not clear:
in Express this becomes:
but if we try to update the array with this syntax:
it becomes:
The Sorry this is long winded but I'm trying to show some special syntax might be required to make this work. |
@joelanman does it make sense for [1] to put 'David' into the array at position 1?
|
Joe has let me know this is not under our control since |
I beleive in a implementation I was working with on a prevous project I can across the same issue. I ended up getting around it by using a lodash method to |
I think it would help to have a documented example of adding to a list in the Prototype Kit. |
Following review the Prototype Team are closing this ticket. If the original author wishes to raise this issue again please feel free. |
Currently if a user of the kit tries to set a vlue in a data object (for example a complex object set in
session-data-defaults.js
) by using an input like<input name="defaults.accounts[3].name" value="Ellie Sattler"/>
thedefaults
object will be overwritten with a new object including only the new data.The expected behavior would be that the
name
for 4thaccount
indefaults
will equalEllie Sattler
and all other data would remain unchanged.After some investigation it looks like the way the
req.query
handles incoming keys it converts any string to an object so it flattens into a single object and uses this to replace the root object. I have added a workaround which involves sending and 'selector' and the 'value' inside thevalue
of the input (to preserve its 'string-y-ness) and using special characters in the name or key to handle it seperatly in thestoreData()
method. For examplename=":set:" value="defaults.accounts[3].name=Ellie Sattler"
And then:
This implementation has the added benefit of allowing whole object replacement if required and maintains backwards compatibility.
The text was updated successfully, but these errors were encountered: