TWebDBEdit created at runtime does not show DataSet data.

TWebDBEdit created at runtime does not show DataSet data.

I'm creating a TWebDBTableControl and placing an input inside the cell to be able to edit the value, and I'm creating a TWebDBEdit and binding the ElementID of the input and binding the TWebDBEdit to my TXDataWebDataSet, but the value does not appear in the TWebDBEdit .

Cannot be reproduced.
Tested this with DataSet demo and code added to unit1.html was:
<input id="mydbedit" value="test">
and code to create TWebDBEdit at runtime:

procedure TForm1.WebButton2Click(Sender: TObject);
var
  dbe: TWebDBEdit;
begin
  dbe := TWebDBEdit.Create('mydbedit');
  dbe.DataSource := WebDataSource1;
  dbe.DataField := '_Species_Name';
end;

and this works as expected.

I couldn't simulate in the Dataset example so I detailed the problem more.

I have this TWebDBTableControl that lists the data from a TXDataWebDataSet, and when I click on the button like + to insert the data I create the INPUTs in the Table's cells at runtime and create the TWebDBEdit and link the ElementID of the Input to the Edits and I link the TXDataWebDataSet of the products to the Edits.

When I click on the Magnifying Glass in the ID field, a modal form opens for me to search for the product, when I select it I close the search screen and pass the values to the TXDataWebDataSet of the product:

cdsProduto.FieldByName('PRODUTO').Value                   := TJSJSON.parseObject(TJSJSON.stringify(TJSObject(DataWebDataSet.CurrentData)));
cdsProduto.FieldByName('ID_PRODUTO').AsInteger            := DataWebDataSet.FieldByName('ID').AsInteger;
cdsProduto.FieldByName('CODIGO_INTERNO_PRODUTO').AsString := DataWebDataSet.FieldByName('CODIGO_INTERNO').AsString;
cdsProduto.FieldByName('NOME_PRODUTO').AsString           := DataWebDataSet.FieldByName('NOME').AsString;

Here is the complete code of the routine:

procedure TFViewPedidoVendaEdit.btnIncluirProdClick(Sender: TObject);
var
  XField: TField;
  RecordId: Integer;
  edtCampo: TWebDBEdit;
  i, indexRow: Integer;
  elemento: TJSElement;
  value, defaultValue: String;
  Pesq: String;
  btnIdProd: TWebButton;
begin
  cdsProduto.insert;

  btnIncluirProd.Visible := False;
  btnAlterarProd.Visible := False;
  btnSalvarProd.Visible  := True;
  btnExcluirProd.Visible := False;
  btnCancelarProd.Visible := True;

  gridProduto.InsertRow(1);

  for i := 0 to Pred(gridProduto.Columns.Count) do
  begin

    edtCampo := TWebDBEdit.Create('gridProd'+gridProduto.Columns[i].DataField+IntToStr(1));
    edtCampo.BeginUpdate;
    edtCampo.Name       := 'edt'+gridProduto.Columns[i].DataField+IntToStr(1);
    edtCampo.DataField  := gridProduto.Columns[i].DataField;
    edtCampo.DataSource := dsProduto;

    XField := cdsProduto.FindField(gridProduto.Columns[i].DataField);

    case XField.DataType of
      ftDateTime,ftDate,ftTime:
      begin

      end;
      ftBoolean:
      begin

      end;
      ftLargeint,ftInteger:
      begin
        edtCampo.EditType := weNumeric;
      end;
      ftFloat:
      begin
        edtCampo.EditType := weFloat;
      end;
      ftString, ftMemo:
      begin
        edtCampo.EditType := weString;
      end;
    end;

    edtCampo.EndUpdate;

    if gridProduto.Columns[i].DataField = 'ID_PRODUTO' then
    begin
      Pesq := '<div class="input-group">'+
              '  <input id="gridProd'+gridProduto.Columns[i].DataField+IntToStr(1)+'" type="text" class="form-control form-control-sm"/>'+
              '  <button id="prod.btnIdProd" class="btn btn-primary py-0" type="button">'+
              '    <i class="fas fa-search"></i>'+
              '  </button>'+
              '</div>';

      gridProduto.Cells[i,1] := Pesq;

      btnIdProd := TWebButton.Create('prod.btnIdProd');
      btnIdProd.OnClick := @PesqProdButtonClick;
      btnIdProd.Name := 'btn'+gridProduto.Columns[i].DataField+IntToStr(1);
    end
    else
      gridProduto.Cells[i,1] := '<input id="gridProd'+gridProduto.Columns[i].DataField+IntToStr(1)+'" type="text" class="form-control form-control-sm"/>';
  end;
end;
procedure TFViewPedidoVendaEdit.PesqProdButtonClick(Sender: TObject);
  procedure AfterShowModal(DataWebDataSet: TXDataWebDataSet; ModalResult: TModalResult);
  var
    produto: string;
  begin
    if(ModalResult = mrOk)then
    begin
      if not(DataWebDataSet.IsEmpty)then
      begin
        produto           := DataWebDataSet.FieldByName('NOME').AsString;
        cdsProduto.FieldByName('PRODUTO').Value                   := TJSJSON.parseObject(TJSJSON.stringify(TJSObject(DataWebDataSet.CurrentData)));
        cdsProduto.FieldByName('ID_PRODUTO').AsInteger            := DataWebDataSet.FieldByName('ID').AsInteger;
        cdsProduto.FieldByName('CODIGO_INTERNO_PRODUTO').AsString := DataWebDataSet.FieldByName('CODIGO_INTERNO').AsString;
        cdsProduto.FieldByName('NOME_PRODUTO').AsString           := DataWebDataSet.FieldByName('NOME').AsString;

      end;
    end;
  end;
begin
  TFViewPesquisa.Pesquisa(@AfterShowModal,'PRODUTO', 'Pesquisa Produto', 'EXCLUIDO eq False and ATIVO eq True and TIPO_VENDA eq True');
end;

Sorry but these partial code snippets are not a workable starting point for us to decipher what you could potentially do wrong. We cannot reconstruct a test project based on this.

I'll make an example and post it here.

Follow the test project

Unit1.dfm (6.8 KB)
Unit1.html (1.4 KB)
Unit1.pas (4.6 KB)
TMSWeb_Dataset.dproj (7.8 KB)
TMSWeb_Dataset.dpr (262 Bytes)
index.html (935 Bytes)

So, what do I need to do in this app?!

I click "Connect to DB" and then "Include data" and nothing happens.

Click to include a new record in the navigator which will create a line in the table with the edits and then click on include data which will be assigned the values for the edits, you will see that in the example that already exists it includes it but in the grid it does not

I discovered the problem that when I assign a value to a field it does not appear in the input, when creating edits and inputs at runtime you first need to create the HTML tag of the input and assign it to the element that is the cell and only then create the DBEdit passing the ElementID of the Input to the DBEdit, if you create the component first and assign the ElementID of an HTML tag that doesn't exist, it doesn't know who its relative is.

If you set an ElementID to a value of a HTML element that does not exist, expect things will fail.
The object cannot continue to work properly in these circumstances.

The problem I'm having now is when I have a master/detail and I insert a new record but it's a new detail record, when inserting a record as the detail edition is in GRID I insert a new line in the grid GRID.insertRow(1 ).

I always assign the value 1 to create the first line, and then I create the HTML Tag INPUT for the grid line to be editable.

Search := '<div class="input-group">'+
          ' <input id="gridProd'+gridProduct.Columns[i].DataField+IntToStr(1)+'" type="text" class="form-control form-control-sm"/>'+
          ' <button id="prod.btnIdProd" class="btn btn-primary py-0" type="button">'+
          ' <i class="fas fa-search"></i>'+
          ' </button>'+
          '</div>';

gridProduct.Cells[i,1] := Search;

The problem that occurs is that inspecting the HTML does not show this PESQ Tag with the Input and the line created was not created in the Body of the Table, but in the THEAD element.

Again, cannot be reproduced.

procedure TForm1.WebButton1Click(Sender: TObject);
begin
  webtablecontrol1.InsertRow(1);
  webtablecontrol1.Cells[1,1] := 'abc <input type="button" value="OK">';
end;

If you submit problem reports, then please isolate these and send a sample project clearly demonstrating the problem so we can investigate it efficiently.

If you test there just calling your TWebDBTableControle.InsertRow(XXX) it will insert in thead and not in the body.

Again, CANNOT be reproduced

dbtablecontrolinsertrow

If you submit problem reports, then please isolate these and send a sample project clearly demonstrating the problem so we can investigate it efficiently.