[xwiki-devs] Change Title On Save
I have a form. I want the title to be changed to a combination of two fields on the form whenever it is saved. Can someone point me in the right direction to learn how to accomplish this? Sorry if this is a newbie question. -- View this message in context: http://xwiki.475771.n2.nabble.com/Change-Title-On-Save-tp7589667.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
Do you really want the title to _store_ the 2 fields or you only expect it to _display_ the 2 fields? I assume it is the second case. You can use velocity in the title field of a document. So you can do something like: $doc.get('field1') - $doc.get('field2") I hope it helps, LM 2014-03-18 20:23 GMT+01:00 DeHaynes <[email protected]>:
I have a form. I want the title to be changed to a combination of two fields on the form whenever it is saved. Can someone point me in the right direction to learn how to accomplish this?
Sorry if this is a newbie question.
-- View this message in context: http://xwiki.475771.n2.nabble.com/Change-Title-On-Save-tp7589667.html Sent from the XWiki- Dev mailing list archive at Nabble.com. _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Can I expose the Title/Document Name as a field to be updated? -- View this message in context: http://xwiki.475771.n2.nabble.com/Change-Title-On-Save-tp7589667p7589708.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com.
Maybe if I explain in better detail. I am creating 3 forms. 1. Person 2. Department 3. Company The idea is that there is a Person document for each company. In the Company Form, there is a Department TextArea section. In that section would be links to various Department Forms. In the Department Form, there is a Personnel TextArea section. In that section would be links to various Person Forms for people who work in that department. I would like to standardize the forms to have a consistent document name and title. They would be: 1. Person - FirstName and LastName 2. Department - Department Name 3. Company - Company Name I would like to save the document name and title when they save the document. For Company and Department, if I could expose the Title field to be edited by the user and just give it the "Department Name" or "Company Name" label, then that would work. For the Person Form, I would have to combine two fields with a space between them. I thought of using a JavascriptExtension to do this. I saw where you can listen for the save event. Unfortunately I could not find how to reference the various fields of the document from JavaScript. -- View this message in context: http://xwiki.475771.n2.nabble.com/Change-Title-On-Save-tp7589667p7589709.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com.
2014-03-19 21:22 GMT+01:00 DeHaynes <[email protected]>:
Maybe if I explain in better detail. I am creating 3 forms. 1. Person 2. Department 3. Company
The idea is that there is a Person document for each company.
In the Company Form, there is a Department TextArea section. In that section would be links to various Department Forms.
In the Department Form, there is a Personnel TextArea section. In that section would be links to various Person Forms for people who work in that department.
I would like to standardize the forms to have a consistent document name and title. They would be: 1. Person - FirstName and LastName
In the title of your sheet: #set($obj = $doc.getObject('myClass'))$obj.display('firstName', 'view') $obj.display('lastName', 'view')
2. Department - Department Name
In the title of your sheet: #set($obj = $doc.getObject('myClass'))Department: $obj.display('departmentName', 'view')
3. Company - Company Name
In the title of your sheet: #set($obj = $doc.getObject('myClass'))Company: $obj.display('companyName', 'view') And please see: http://extensions.xwiki.org/xwiki/bin/view/Extension/Sheet+Module for more informations about the Sheet system. I hope it helps, Louis-Marie
Thank you very much for your response. While this does change the Title that is displayed on the form, it doesn't change the name of the document. I researched and found the following command in the API. $doc.rename($doc.display('departmentName')) I need to figure out how to apply it just before a save event. -- View this message in context: http://xwiki.475771.n2.nabble.com/Change-Title-On-Save-tp7589667p7589726.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com.
If you want to change the document name, it is more complicated, indeed. I think you should dig into the javascript area. 2014-03-20 14:07 GMT+01:00 DeHaynes <[email protected]>:
Thank you very much for your response. While this does change the Title that is displayed on the form, it doesn't change the name of the document. I researched and found the following command in the API.
$doc.rename($doc.display('departmentName'))
I need to figure out how to apply it just before a save event.
-- View this message in context: http://xwiki.475771.n2.nabble.com/Change-Title-On-Save-tp7589667p7589726.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com. _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
I thought so also, so I looked into the JavascriptExtension and put the following code into it. document.observe("xwiki:actions:saved", function(event){ var doContinue = event.memo['continue']; if (doContinue) { alert('Saved It.'); } }); The alert did not fire when I clicked the saved button. So I moved the alert outside of the "If" block. It still did not fire. While digging into this further, it occurred to me that I cannot just change the value of some "DocumentName" field on the form because the document document name is not on the form. So I would have to reach into the XWiki object model somehow. I could not find an example of that or an API listing. I decided to drop this researching the javascript solution because what I really want to happen is going to occur at the server, not the browser. So I am not trying to figure out if there is another way to approach this. I would love to know your thoughts on my logic. That could help me determine which way is the correct way to accomplish this. Thank you. -- View this message in context: http://xwiki.475771.n2.nabble.com/Change-Title-On-Save-tp7589667p7589731.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com.
2 approaches: 1 (easy) - write a form with some fields that create a new document with a computed name. It will not rename the document if you change the fields afterwards, but depending on your use-case, it might be enough. 2 (more complex) - write a listener component that rename the document, if needed, every time a document is saved. It needs to be written in Groovy or in Java. See: http://platform.xwiki.org/xwiki/bin/view/DevGuide/GroovyNotificationTutorial... http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents Louis-Marie 2014-03-20 15:53 GMT+01:00 DeHaynes <[email protected]>:
I thought so also, so I looked into the JavascriptExtension and put the following code into it.
document.observe("xwiki:actions:saved", function(event){ var doContinue = event.memo['continue']; if (doContinue) { alert('Saved It.'); } });
The alert did not fire when I clicked the saved button. So I moved the alert outside of the "If" block. It still did not fire.
While digging into this further, it occurred to me that I cannot just change the value of some "DocumentName" field on the form because the document document name is not on the form. So I would have to reach into the XWiki object model somehow. I could not find an example of that or an API listing. I decided to drop this researching the javascript solution because what I really want to happen is going to occur at the server, not the browser.
So I am not trying to figure out if there is another way to approach this. I would love to know your thoughts on my logic. That could help me determine which way is the correct way to accomplish this.
Thank you.
-- View this message in context: http://xwiki.475771.n2.nabble.com/Change-Title-On-Save-tp7589667p7589731.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com. _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
2014-03-20 16:20 GMT+01:00 Guillaume "Louis-Marie" Delhumeau < [email protected]>:
2 approaches:
1 (easy) - write a form with some fields that create a new document with a computed name. It will not rename the document if you change the fields afterwards, but depending on your use-case, it might be enough.
Note: this approach does not require you to know the Java language. It is not the perfect solution, but I often do that. Louis-Marie
participants (2)
-
DeHaynes -
Guillaume "Louis-Marie" Delhumeau