Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have an OpenLayers pop-up with a form on selectFeature (WFS-T). Can I recover the feature.attributes in the form's onSubmit?

e.g: the form in the popup

var content = '<form onSubmit="processForm(this.form)">' +
    'Träd-Id<br><input type="text" name="trädnummer" value="' +
    feature.attributes.trädnummer + '">' +
    '<br>Art<br><input type="text" name="art" value="' +
    feature.attributes.art + '">' +
    '<br>Anmärk.<br><textarea name="anmärkningar" rows="4" cols="40">' +
    feature.attributes.anmärkningar + '"</textarea>' +
    '<br>Åtgärd<br><textarea name="anmärkningar" rows="4" cols="40">' +
    feature.attributes.rekommendationer + '"</textarea>' +
    '<br><input type="submit" value="Spara""></form>'

and the onSubmit callback:

function processForm(oForm) {
  var feature = **recover currently selected feature here?**
  feature.attributes.trädnummer = 
    oForm.elements["trädnummer"],value;
  feature.attributes.art = 
    oForm.elements["art"],value;
  feature.attributes.anmärkningar = 
    oForm.elements["anmärkningar"],value;
  feature.attributes.rekommendationer = 
    oForm.elements["rekommendationer"],value;
  return false;
}

If so, I thought I could use WFS-T to update the attribute info? (instead of e.g. a post to php) Any help appreciated
Thanks Mini

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Just a thought: you can add a hidden field in the form with id of your feature and then reach the feature itself (so attributes too) by this id (via getElementById) in onSubmit callback.

share|improve this answer
    
Thanks @unibasil - that's sorted it. I also got rid of the <form> and onSubmit stuff and used the WFS-T I'd already set up (feature.state = OpenLayers.State.UPDATE; saveStrategy.save(); in a button click handler). I'll post the updated code. –  minisaurus Mar 26 '13 at 7:54
    
Forgot to mention, I added ids based in feature.id in the input fields and used getElementById to recover the inputs in the button click handler. I used this.wfs.selectedFeatures[0] to get to the attributes in the button click handler –  minisaurus Mar 26 '13 at 7:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.