Re: Rép. : Re: [Cartoweb-users] Using dropdown menu to fill attribute in the editmodule

Oliver Christen oliver.christen at camptocamp.com
Wed Aug 9 07:49:14 EDT 2006


in the Map.prototype.editTableAddRow = function(table, aFeature) function 
(in dhtmlEdit.js)

note, this is untested, i dont have a project with editable layers under the 
hand at the moment
I have added a few comments in the code that should help you, I have made 
the supposition the attribute name that require the select was 
''typeOfRoad'', replace it by your own.
authorisedOptionsList and authorisedOptionsListLabel are two array 
containing the options value and label (whats the user can see in the list)
if you need language translation, simply add them in your template instead 
of in the js file to be able to use the smarty translations function 
{t}..{/t}
(
<script type="text/javascript">
  /*<![CDATA[*/
    var authorisedOptionsListLabel = new Array('{t}Path{/t}', '{t}Road{/t}', 
'{t}Main road{/t}');
  /*]]>*/
</script>
)


replace


      var input = createInput(td,
        "edit_feature_" + aFeature.id + "[" + this.editAttributeNames[i] + 
"]", value, 'text')
      input.onkeypress = function() {
        if (!this.changed) {
          if (aFeature.operation != 'insert')
            setFeatureOperation(aFeature, "update");
          var validate = xGetElementById('validate_all');
          validate.className = "form_button_hilight";
          if (editDisplayAction != 'folder'){
            var validate = xGetElementById('validate2');
            validate.className = "form_button_hilight";
          }
        }


by


// in case the attribute name is the one that must be a select
if (editAttributeNames[i] == 'typeOfRoad') {
    // create the select element
    var str = '<select name="'+this.editAttributeNames[i]+'" />';
    var input = xCreateElement(str);

    var authorisedOptionsList = Array('path', 'road', 'main_road');
    var authorisedOptionsListLabel = Array('Path', 'Road', 'Main road');
    // for each options add an option element in the select
    for (var j = 0; j < authorisedOptionsList.lenght; j++){
      input.options[i] = new 
Option(authorisedOptionsListLabel[i],authorisedOptionsList[i]);
    }
    // insert the select into the td
    xAppendChild(td, input);

      // some background properties that need to be set, in the case of 
select, onchange events instead of onkeypress
      input.onchange = function() {
        if (!this.changed) {
          if (aFeature.operation != 'insert')
            setFeatureOperation(aFeature, "update");
          var validate = xGetElementById('validate_all');
          validate.className = "form_button_hilight";
          if (editDisplayAction != 'folder'){
            var validate = xGetElementById('validate2');
            validate.className = "form_button_hilight";
          }
        }

} else {
      var input = createInput(td,
        "edit_feature_" + aFeature.id + "[" + this.editAttributeNames[i] + 
"]", value, 'text')

      input.onkeypress = function() {
        if (!this.changed) {
          if (aFeature.operation != 'insert')
            setFeatureOperation(aFeature, "update");
          var validate = xGetElementById('validate_all');
          validate.className = "form_button_hilight";
          if (editDisplayAction != 'folder'){
            var validate = xGetElementById('validate2');
            validate.className = "form_button_hilight";
          }
        }
}


----- Original Message ----- 
From: "Edouard Legoupil" <LEGOUPIL at unhcr.org>
To: <oliver.christen at camptocamp.com>; <cartoweb-users at lists.maptools.org>
Sent: Wednesday, August 09, 2006 10:15 AM
Subject: Rép. : Re: [Cartoweb-users] Using dropdown menu to fill attribute 
in the editmodule


Dear Oliver,

Thanks for this precision. Would it be possible to give me quick example ?

Imagine i have a table called road, one colonn is typeof and i would like to 
restrict the choice for this specific field to "path", "road" and "main 
road"

Thanks and regards
Edouard

>>> "Oliver Christen" <oliver.christen at camptocamp.com> 08/08/2006 12:54 >>>
There is, but not easily

the table containing the edition form is generated in javascript by
dhtmlEdit.js, especially look in the functions Map.prototype.editTableAddRow
( see the var input = createInput(...) on line 516-517 for en exemple of
input generation )

Regards
Oliver

> Dear all,
>
> I am building an edtion interface to edit online various object. To
> represent those new objects, i will use different class from the
> attributes filled by users.
>
> Therefore i would like to restrict their choice when they will fill the
> attributes
>
> Is there a way to implement dropdown menu on these fields ?
>
> Thanks for your support
>
> Edouard
>
>
> _______________________________________________
> Cartoweb-users mailing list
> Cartoweb-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/cartoweb-users
>





More information about the Cartoweb-users mailing list