Extension talk:Semantic Forms

From MediaWiki.org
Jump to: navigation, search
An archive box Archives 

Make form generate <noinclude> </noinclude> tags in the resulting article[edit | edit source]

I want a form to generate an article that has <noinclude> </noinclude> tags in the article itself (around the properties table). This is because later on, when i embed/transclude that article in another, i do not want the properties table to show - only the article proper (free text). Maybe i'm missing something very basic here - i'm still quite new to smw. So far, in the form definition, i tried wrapping the <noinclude> tags in <nowiki> tags - to no avail. Maybe including <noinclude> tags isn't even necessary. Maybe there is another way, how to embed articles without displaying their properties table? Any advice greatly appreciated :) Andi 3ö (talk) 13:25, 3 April 2015 (UTC)

See "onlyinclude free text", here. Yaron Koren (talk) 23:07, 5 April 2015 (UTC)
Ooops, didn't see that. Thank you so much!! Andi 3ö (talk) 21:22, 7 April 2015 (UTC)

Templates, how to introduce categories instead of properties[edit | edit source]


So actually i have this template:

Try template


Edit the page to see the text in template

</noinclude><includeonly>{| class="wikitable"
! Departments
| {{#arraymap:{{{Departments|}}}|,|x|[[Dep::x]]}}
! Autor
| [[Autor::{{{Autor|}}}]] 

Which will add the thing i add to Departments and autor to those properties. I want, instead, to add them to categories. How can i do this?

I tried with this:


And this


But i do not manage that when someone fills the field, things get in the correct category. How could i do this?

Change it to something like this:
! Departments
| {{#arraymap:{{{Departments|}}}|,|x|[[Category:x]] [[:Category:x]]}}
! Autor
| [[Category:{{{Autor|}}}]] [[:Category:{{{Autor|}}}]]
Yaron Koren (talk) 21:00, 7 April 2015 (UTC)

Actually that is not working for me, i tried, but seems the boxes to fill in the form will only show an string instead. Perhaps it can be a problem with versions? Using MW 1.24.1 AND SF 3.2. All the tries i have made have resulted in an string as output, or something which did not do the thing.

Could you post an example which it is known to work please?

It's important to clarify that the form and the template are two different things - you asked about the template before, not the form. For the form, I don't know what input you want those fields to be, but the "tree" input type might be helpful. Yaron Koren (talk) 13:50, 8 April 2015 (UTC)

Sorry! I meant the template. I made a mistake there! I mean that is not working in my template. Could i have an example of how to make the template do that please?

That was my first response. Yaron Koren (talk) 20:21, 8 April 2015 (UTC)

Still not working, but perhaps it is a formulated the question badly.

Ok, this is the situation, i want a form to use the template, and do what i told.

In the form we will have 2 text box to fill, "Autor" and "Departments".

| [[Category:{{{Autor|}}}]] [[:Category:{{{Autor|}}}]]

this for example, will add the page created with the form to "value entered in "Autor field" " category, and in the "Autor" field of the page, it will put "category:"entered value"", but will not do what i am asking for. Hope i got clearer now!

What is it that you're asking for? Yaron Koren (talk) 01:16, 9 April 2015 (UTC)

I want to know what do i have to put in my template so that when someone fills a text box in my form (for example, the mentioned "Autor" or "Departments"), which are taken from the template to the form.

I get the syntax of

[[Category:]]-> This means the page created with the form, will receive

[[Category:"What it is put on "Autor text box".]]
[[:Category:{{{Autor|}}}]]-> This instead, means that in the !Autor box of the created page, we will have [[Category:"What it is put on "Autor text box".]](all of it, as an String).

In both ocasions there are 2 individuals working(Indication of category and what user writted). But what i am asking for is the syntax of 3 individuals working.

I need 1º what the User has written


, 2º the indication that value is going to be in a category


, 3º which category will it be "Autor". For example

{{{Autor|}}} [[Category:Autor]]

, but this is not the syntax. Which would be?

Oh, I made a small mistake in my original example. Try this:
! Departments
| {{#arraymap:{{{Departments|}}}|,|x|[[Category:x]] [[:Category:x|x]]}}
! Autor
| [[Category:{{{Autor|}}}]] [[:Category:{{{Autor|}}}|{{{Autor|}}}]]
...or, if you want to keep things simple, this:
! Departments
| {{#arraymap:{{{Departments|}}}|,|x|[[Category:x]] x}}
! Autor
| [[Category:{{{Autor|}}}]] {{{Autor|}}}
Yaron Koren (talk) 01:59, 9 April 2015 (UTC)

Actually this is kind of what i was looking for:

! Autor

It manages to redirect what it is in


to the category i want "Autor", although it does not introduce it. This is kind of a redirect. So that i will have a box in which i will click in the introduced value and i will be redirected to "Autor", but not introduce the value itself to the category. Any solution?

Did you try what I suggested? Yaron Koren (talk) 12:11, 9 April 2015 (UTC)

Yes, copy pasted both types, but did not do the thing. The closest thing i found was that which i told, which is still not what i want :S.

So there is no way of doing what i am asking for? Have tried all the suggestions, still, nothing :s. ATM we have reached the possibility of accessing the wanted category from the template, but still creating an individual inside of a category from the template is needed.

Are you sure you fully tried the suggestions I gave? Any of those three should achieve what you're trying to do. Yaron Koren (talk) 12:55, 13 April 2015 (UTC)

100% sure. I have made a showcase showing and explaining what does each thing do:


Please, have a look. I would recommend you trying them otherwhise, but you will get the same result.

Oh... now I think I get it! You want those values entered by the user to become part of another category - I thought that you wanted those values to be category names. If that's correct, then there's no way to do that from within the page - you can't specify, on page A, that page B should be part of category C. Instead, the user will have to go to each of those pages and handle the tagging there - through a form or otherwise. Yaron Koren (talk) 17:07, 13 April 2015 (UTC)

Ok, thanks a lot mate. Will leave it that way then, tough, it would be awesome to have the oportunity to do so to link categories between them.

Getting CSS codes in dropdown list items when using a mapping template[edit | edit source]


I recently update SForms to 3.2 and now get <div class=\"smwpre\">$result</div> tags around dropdown list items. The list items themselves use a mapping template as I'm using semantic title to provide an alternative name for the pages. I've had this working in the past but have just noticed I now get the CSS tags.

I wondered if anyone has encountered this before or got any idea what might cause it?

Many thanks




I've spent a little more time investigating this. I find if I change line 95 in /includes/forminputs/SF_DropdownInput.php from

$innerDropdown .= Html::element( 'option', $optionAttrs, $label );


$innerDropdown .= Html::rawElement( 'option', $optionAttrs, $label );

then the dropdown displays its list items correctly without the CSS tags. I have to admit I don't really understand the difference between the two functions so it would be nice to know if I'm unwittingly introducing a risk. I'm also a little concerned I'm now running a non-standard version of this file so wondered if I'm missing something and should be achieving this effect in another way? By the way, a combobox field seems to work fine as an alternative for achieving the same thing, its just the dropdown looks neater for this usage, I think.

Many thanks

Duncan (18 April 2015)

Sorry about not responding before - I didn't realize that, when you said that <div> tags appear, you meant that they literally appear on-screen - which is bad, of course. Your proposed solution seems reasonable. I don't know if it's introducing a security risk - it's possible. But if you're running a private wiki, it's probably not a big deal.
As to the original issue - I'm guessing that Semantic Title is the culprit, in one way or another, but I don't know more than that. Or did this work correctly with the same versions of Semantic Title, SMW and MW, but an earlier version of SF? Yaron Koren (talk) 01:08, 19 April 2015 (UTC)
Hi Yaron
I think it was working OK with the earlier version of Semantic Forms (as I'd certainly have noticed ) but I've looked back at the last few versions and the code seems the same! I've introduced some other extension so maybe its something to do with those. I did notice that when Html class is used elsewhere in the dropdown input field it uses Html::rawElement rather than Html::element which is why I tried it on line 95. Given this, I'm hoping it should be OK.
I checked the documentation and the difference is that the content string is escaped in Html::element and not in Html::rawElement.
Many thanks, Duncan (19 April 2015)
Everything you're saying makes sense except for the fact that it used to work correctly, with an older version of SF (though it couldn't have been that much older, if you were using "mapping template"). Are you sure about that? And do you remember what SF version it was? Yaron Koren (talk) 15:23, 20 April 2015 (UTC)
Hi Yaron
Yes it seemed unlikely to me also that the same code would produce different results. I even thought maybe I'd used Combobox instead but I checked back and found it was Dropdown. I still have the prototype that worked and I checked the versions. However I find the versions of SF, MW and SemanticTitle are all the same as the current prototype that doesn't (SF3.2, SemanticTitle 2.1, SMW2.0). So I think it must be some other change I've made not SemanticTitle or SF. When I have time I'll try eliminating changes one by one to get to the root of it!
Thanks as always for your help
Duncan (21 April 2015)
Woops - now I realise I have been incredibly dense. I operate a wiki-farm so of course the earlier prototype was running under the same code which had been upgraded and had my 'fix' in. When I regressed to the earlier versions of semantic forms, it appears that the Dropdown field type had never worked with the Mapping Template and this version of Semantic Title. So I must investigate further. Interestingly, if I use the Combobox field type to emulate a Dropdown, I don't get this problem.
Duncan April 24, 2015
Doh - now I really feel a numpty. The property holding the Semantic Title had a data type of Code. When I changed it to Text all worked fine! Oh well, if any one else strays this way then perhaps I'll have saved them some time :-)
Duncan 24 April, 2015
Ah, that would explain it. I'm glad you found the problem. Yaron Koren (talk) 18:48, 24 April 2015 (UTC)

Does "show on select" only saves the presently displayed form inputs and omit the hidden ones?[edit | edit source]

I use "show on select" in multiple forms to switch among 7 form parts which are all very detailed, I use it to mimic a step by step form input. When I preview the form and submit it I only see the presently shown form part to be parsed in the preview, the other hidden but filled form parts remain in the form but do not get to the preview.

  1. It seems that "show on select" only evaluates the selection that is presently shown and dismisses all other hidden but filled form fields. Is this standard behaviour or a BUG?
  2. How can I accomplish to switch among form parts that all get translated even the hidden filled form fields? Write my own JavaScript program? (I could use the JavaScript mw-collapsible mechanism but on a new multiple form part it dos not work because it is not yet bound to the onclick event of button “Add new”. A work around using jQuery.on(…) would solve it but needs extra JavaScript programming. PS: widgets tabs or accordion of jQuery-UI would close come to my needs but that’s not possible with default Semantic Forms?)

Thanks for any solution --Andreas P. Icon External Link E-Mail.png 11:06, 10 April 2015 (UTC)

"show on select" is meant to truly remove stuff from the form, so what you're seeing is correct behavior - trying to use it for a wizard is clever, but probably won't work, as you've seen. And yes, it's too bad that the "collapsible" stuff doesn't work in multiple-instance templates. Though I'm trying to figure what your form looks like, though - is it basically like a wizard within each instance of a multiple-instance template setup? If so, that's complex! The Header Tabs extension is the standard way in which people set up wizard-style functionality in forms, but that won't work if you have more than one wizard. Yaron Koren (talk) 15:38, 10 April 2015 (UTC)
So I need a "show on select" without the removing procedure (frankly a feature request ;-) or an attribute in the setup of {{{field|…}}} that stores also the hidden inputs. What I like about "show on select" is, that you can hide much stuff until you need it. But as you pointed out it is originally meant to remove hidden form inputs before save. :-( --Andreas P. Icon External Link E-Mail.png 16:07, 10 April 2015 (UTC)
Is there an official way to integrate custom JavaScript functions in Semantic forms, especially to “Add another” ? I wrote a custom tool that works [1], but not when I click “Add another”. Is there a way? --Andreas P. Icon External Link E-Mail.png 21:37, 23 April 2015 (UTC)
Yes - using the relatively new JS hook "sf.addTemplateInstance". See here for how it can be called. Yaron Koren (talk) 23:22, 23 April 2015 (UTC)
Thanks, very good. And how can I check in a sustainable manner if the form is in edit mode (action=formedit …). I do it with
if(mw.config.get( 'wgAction' )==="formedit" 
|| mw.config.get( 'wgCanonicalSpecialPageName' )==="FormEdit"){// when Special:FormEdit
  // do stuff to be executed during form editing (including preview form result?)
I'm not sure if preview was clicked that sometimes the URL becomes action=submit during form editing, and so I have to check also for action=submit. That of course is also present on every preview that is a non-form preview. So do I need correct above check or is there another “official” way? --Andreas P. Icon External Link E-Mail.png 09:55, 24 April 2015 (UTC)
That one I don't know. Yaron Koren (talk) 13:08, 24 April 2015 (UTC)
OK with the hook sf.addTemplateInstance it works, but I got it only working when writing
(1) mw.hook('sf.addTemplateInstance').add(my_custom_function).fire(my_custom_function);
with (2) mw.hook('sf.addTemplateInstance').fire(my_custom_function); it works only when the form is loaded the first time. So I wonder if (1) is needed here to get it work regularly. --Andreas P. Icon External Link E-Mail.png 14:24, 24 April 2015 (UTC)