Duplicate block field#438
Conversation
|
This is awesome! |
|
Looks Good Hi @lukecarbis, Initial FieldDuplicateAll of the fields that I tested had all of their values duplicated. Including Text, Post, and Checkbox. |
| */ | ||
|
|
||
| (function( $ ) { | ||
| /* global blockLab, jQuery */ |
There was a problem hiding this comment.
Wow, this is great. It looks like this now passes eslint!
What do you think of adding it to the eslint configuration?
diff --git a/package.json b/package.json
index c5cd510..6c7cf1a 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,7 @@
"dev": "cross-env BABEL_ENV=default webpack --watch",
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",
"lint": "npm-run-all --parallel lint:*",
- "lint:js": "eslint js/blocks",
+ "lint:js": "eslint js",
"lint:js:fix": "eslint js/blocks --fix",
"lint:php": "vendor/bin/phpcs",
"lint:php:fix": "vendor/bin/phpcbf"Also, creating an .eslintignore with the following will prevent it from running on the compiled files:
js/editor.blocks.js
js/scripts.js|
Side Note We might consider refactoring this Edit Block UI in React at some point (though not necessarily re-designing it much): js/admin.block-post.js had been long before, and is now 458 lines. The DOM manipulation in that file gets really complex, and it's going to be hard to maintain. And that file's probably not going to get smaller 😄 |
|
Hey all,
Great work @lukecarbis This is a really useful feature! |
There was a problem hiding this comment.
Great work!
Hi @lukecarbis,
Wow, this works well, even duplicating entire repeaters.
Duplicating single fields and repeater rows also work well.
It might be good to refactor the 'Edit Block' screen with React soon.
admin.block-post.js is over 500 lines, and will only get harder to refactor. Though it's worked really well, very few bugs.
|
You guys. Thanks for testing, but you missed a critical bug! Repeater child fields aren't saving. Will take a look at it asap. |
|
The bug is occurring because we're assigning the sub-fields their parent's UID instead of their parent's slug. Actually, this made me realise that saving sub-fields with the parents name is a bad idea! It surfaced a new bug: If you create a repeater, add sub fields, then go back and change the repeater's name, then the sub fields will be deleted on save. I'm going to refactor the sub fields to use the parent UID instead of the parent slug / name. |
|
@kienstra and @RobStino – please re-review? Especially testing:
|
|
Yep, that fixes it. |
No, I haven't been able to break this 😄 |
|
Pending any testing you'd like, I think the code is ready to merge. |





Wow! This was a lot more complicated than I thought it would be.
This isn't yet working for repeater fields (but it is for sub-fields).
This PR also includes a whole heap of JS coding standard fixes.
Closes #315.