When the user adds a content type they must enter the name (human readable) and the type (machine readable). It would be nice if the machine readable type were based on the human readable name and got pre-populated when the mouse focus left the name field.
Things we need:
1. A javascript function that will take a string and reduce it so that it is machine readable format (lowercase letters, numbers, and underscores).
2. When the cursor focus leaves the Name field then the javascript needs to pull that name, send it through the function in #1, and populate the type
The motivation for this is that it reduces work for the user and it makes it easier to understand the set of rules for the machine readable format.
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | autogenerate_mrn.patch | 1.31 KB | gabriel. |
| #14 | auto_human_to_machine_field.patch | 1.31 KB | qbnflaco |
| #11 | auto_human_to_machine_field.patch | 1.31 KB | qbnflaco |
| #9 | auto_human_to_machine_field.patch | 1.73 KB | qbnflaco |
Comments
Comment #1
snufkin commentedjust a question: why does the user even need to enter the machine readable type?
Comment #2
gregglesWhile I see where you are going and it makes some sense, I think we need to give users control of this. In the past we've taken that control away (i.e. cck started that way) and it was then added back because users want control of it.
Comment #3
chrisfromredfinThis is assigned to version 7.x-dev, but as a DROP task would we want it implemented in 6.x or 5.x? Should it be a patch in core or should it be a module like "AutoSuggest node-name?"
Comment #4
yched commented@snufkin : for non-occidental languages, you can't always autogenerate a suitable machine name (a-z, _) from the human name.
Comment #5
snufkin commented@yched: thats true I havent thought about this.
It just appeared to me because recently i was introducing Drupal to someone completely new to the CMS, and it seemed completely useless and confusing to give a machine name too.
@greggles: is it a necessary control though? In CCK IMHO all of the controls are important and change behaviour some way, this doesnt really.
And actually if I take what yched said, then is it not possible to do this mapping via JS? Or reversed: if its possible to do it with JavaScript, it should be possible to do it via PHP, automatically.
Comment #6
greggles@cwells: why can't a drop task be for Drupal7?
Since this changes functionality I don't think this would be appropriate for D5 or D6 and it seems awfully small for a contrib module.
Comment #7
chrisfromredfinA DROP task certainly can be for 7.x, I just want it NOW :). I think this is awesome as an idea, and if there were a contrib module for it, I'd use it on all my sites (existing 5x and new 6x sites).
Comment #8
qbnflaco commentedI claim this task!!
Comment #9
qbnflaco commentedHere's the patch. Many thanks to Demitri for all his help!! A beer for him as soon as he's 21! :D
Comment #10
webchickEclipse's .project file got added to this patch by mistake.
Comment #11
qbnflaco commentedok, took out the project file from the patch
Comment #12
webchickMarking back to needs review. :)
Comment #13
Rowanw commentedIt doesn't work in Firefox 2, this is the error output by Firebug:
Comment #14
qbnflaco commentedThe .strtolower method was changed to .toLowerCase This should now work.
Comment #15
Rowanw commentedIt works now.
However, if you change the MRN (machine-readable name) to something else, it will change back as soon as the HRN loses focus again.
I don't think the MRN should change if it already has a value.
Comment #16
mooffie commented- If you're using 'toLowerCase()' then what does the 'i' regexp flag serve?
- Style: isn't
$('#edit-name', context)redundant?- This code converts "One (two)" to "one__two_". Those superfluous underscores aren't nice.
- This code converts "הכל בסבבה ואני בג'ננה" to "_________________". Ditto.
Comment #17
qbnflaco commentedRowanw:
It doesn't seem to happen to me. The 'type' only changes when I make a change to the 'name'. Hmm.. a class gets added that should stop it from changing if the js has changed it once. I'm not sure why this isn't working.
mooffie:
I also agree that if there was already something for the name field, it shouldn't be changed by js anymore. Any idea how I can add that into the JS? I have pretty limited js abilities. Can you suggest something to help internationalize it? Also can you suggest a way of avoiding the '__' issue?
Thanks
Comment #18
gabriel. commentedThis patch should do the trick :) (based off qbnflaco's latest patch).
Let me know if there's anything else I can do to help with this :)
Comment #19
webchickNo patch. :(
Comment #20
gabriel. commentedeek, I thought it went through last time. strange…
hopefully it works this time :)
Comment #21
gabriel. commentedComment #22
dave reidIt would be simpler to just do:
replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/, ''). This will also remove underscores at the beginning of the name.Comment #23
Anonymous (not verified) commentedThe last submitted patch failed testing.
Comment #24
sunThanks for taking the time to report this issue.
However, marking as duplicate of #471018: Generic pattern/js for hiding machine readable names (applied to menu and content types).
You can follow up on that issue to track its status instead. If any information from this issue is missing in the other issue, please make sure you provide it over there.