<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hey guys,</p>
<p>I feel really dumb and I guess I am missing some basic
concept...:</p>
<ul>
<li>I have a layer with two attributes: "text" (string) and "int"
(integer).</li>
<li>I used drag'n'drop form design to have a form with just the
"text" attribute in it.</li>
<li>I added Python Init Code:</li>
</ul>
<p>```<br>
from functools import partial<br>
<br>
def on_ok(layer, feature):<br>
field_idx = layer.fields().indexOf("int")<br>
attribute_changed = layer.changeAttributeValue(feature.id(),
field_idx, 12345)<br>
if not attribute_changed:<br>
raise Exception("Attribute value could not be changed!")<br>
<br>
def my_form_open(dialog, layer, feature):<br>
ok_button = dialog.findChild(QPushButton)<br>
ok_button.clicked.connect(partial(on_ok, layer, feature))<br>
```</p>
<p>So the form does not show an input widget for the "int" field.
But when pressing OK, the code should change the edited feature's
"int" value to 12345.</p>
<p>This works if I edit existing features.</p>
<p>But if I create a new feature, the "int" value will be empty/NULL
instead of 12345.</p>
Any pointers on how to properly update a new feature's attribute
fields, that exist on a layer but are not shown the user with the
QGIS' widgets in the attribute form?
<p>Cheers, Hannes</p>
</body>
</html>