DROP: when the user adds a content type, base the type on the name using javascript

greggles - February 26, 2008 - 17:26
Project:Drupal
Version:7.x-dev
Component:node system
Category:feature request
Priority:normal
Assigned:qbnflaco
Status:duplicate
Description

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.

#1

snufkin - February 26, 2008 - 17:31

just a question: why does the user even need to enter the machine readable type?

#2

greggles - February 26, 2008 - 17:52

While 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.

#3

cwells - February 26, 2008 - 18:29

This 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?"

#4

yched - February 26, 2008 - 19:15

@snufkin : for non-occidental languages, you can't always autogenerate a suitable machine name (a-z, _) from the human name.

#5

snufkin - February 26, 2008 - 20:16

@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.

#6

greggles - February 26, 2008 - 20:40

@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.

#7

cwells - February 26, 2008 - 21:02

A 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).

#8

qbnflaco - March 7, 2008 - 21:21
Assigned to:Anonymous» qbnflaco

I claim this task!!

#9

qbnflaco - March 29, 2008 - 05:44
Status:active» needs review

Here's the patch. Many thanks to Demitri for all his help!! A beer for him as soon as he's 21! :D

AttachmentSizeStatusTest resultOperations
auto_human_to_machine_field.patch1.73 KBIdleFailed: Invalid PHP syntax.View details | Re-test

#10

webchick - March 29, 2008 - 05:48
Status:needs review» needs work

Eclipse's .project file got added to this patch by mistake.

#11

qbnflaco - March 29, 2008 - 14:21

ok, took out the project file from the patch

AttachmentSizeStatusTest resultOperations
auto_human_to_machine_field.patch1.31 KBIdlePassed: 7187 passes, 0 fails, 0 exceptionsView details | Re-test

#12

webchick - March 29, 2008 - 16:11
Status:needs work» needs review

Marking back to needs review. :)

#13

Rowanw - March 30, 2008 - 01:32
Status:needs review» needs work

It doesn't work in Firefox 2, this is the error output by Firebug:

$("#edit-name", context).val().strtolower is not a function
http://localhost/drupal09/modules/node/node.admin.js?E
Line 3

#14

qbnflaco - March 30, 2008 - 02:37
Status:needs work» needs review

The .strtolower method was changed to .toLowerCase This should now work.

AttachmentSizeStatusTest resultOperations
auto_human_to_machine_field.patch1.31 KBIdlePassed: 7187 passes, 0 fails, 0 exceptionsView details | Re-test

#15

Rowanw - March 30, 2008 - 04:45

It 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.

#16

mooffie - March 31, 2008 - 06:04
Status:needs review» needs work

- 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.

#17

qbnflaco - April 1, 2008 - 18:29

Rowanw:
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

#18

gabriel. - June 4, 2008 - 18:47
Status:needs work» needs review

This patch should do the trick :) (based off qbnflaco's latest patch).

  • only generates a new MRN if the field is blank
  • suppresses duplicate underscores
  • removes trailing underscores

Let me know if there's anything else I can do to help with this :)

#19

webchick - June 4, 2008 - 18:51
Status:needs review» needs work

No patch. :(

#20

gabriel. - June 4, 2008 - 21:07

eek, I thought it went through last time. strange…

hopefully it works this time :)

AttachmentSizeStatusTest resultOperations
autogenerate_mrn.patch1.31 KBIdleFailed: Failed to apply patch.View details | Re-test

#21

gabriel. - June 4, 2008 - 21:09
Status:needs work» needs review

#22

Dave Reid - August 28, 2008 - 20:45

It would be simpler to just do: replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/, ''). This will also remove underscores at the beginning of the name.

#23

Anonymous (not verified) - November 11, 2008 - 06:35
Status:needs review» needs work

The last submitted patch failed testing.

#24

sun - August 23, 2009 - 22:52
Status:needs work» duplicate

Thanks 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.

 
 

Drupal is a registered trademark of Dries Buytaert.