Search code examples
javascriptcsstwitter-bootstrapdhtmlx

Get a bootstrap layout for a form inside dhtmlx window


I have a dhtmlx window that contains a form. I would like to get a responsive form with bootstrap classes. My problem right now is that I cannot seem to be able to add my own form inside the window, and I cannot change the className of the fields (like the input field).

I tried to change the className, while creating the form with dhtmlx, but it simply changes the className of the container. I need to change the className of it's elements too, and the parent as well, so Bootstrap can understand it.

I would like to add HTML elements directly if that is possible to the window, in fact. It would be a lot simpler than modding the dhtmlx generated fields.

I made a small JSFiddle to show my problem: http://jsfiddle.net/davidgourde/tnqfp6y8/1/

var myForm, formData;
var dhxWins, w1;
function doOnLoad() {
  formData = [
    {type: "settings", position: "label-left", labelWidth: 100, inputWidth: 120},
    {type: "block", inputWidth: "auto", offsetTop: 12, list: [
      {type: "input", label: "Login", value: "p_rossi", className: "form-control"},
      {type: "password", label: "Password", value: "123"},
      {type: "checkbox", label: "Remember me", checked: true},
      {type: "button", value: "Proceed", offsetLeft: 70, offsetTop: 14}
    ]}
  ];
  dhxWins = new dhtmlXWindows();
  dhxWins.attachViewportTo("vp");
  w1 = dhxWins.createWindow("w1", 10, 10, 300, 250);
  w1.denyResize();
  myForm = w1.attachForm(formData, true);
}
doOnLoad();
div#vp {
  height: 600px;
  border: 1px solid #dfdfdf;
}
<link rel="stylesheet" href="https://2a6781b6e7331b7c52c1706cd28c7de3f641b52b.googledrive.com/host/0B4bedT44-LokVFBFUXlaVEthaFE?t=.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://ecropolis.s3.amazonaws.com/ui/libs/moment.min.js"></script>
<script src="https://344bb70794e57c6753700eb885a1f4eb0c383612.googledrive.com/host/0B4bedT44-LokaV9tODJoX29BVFk"></script>

<div id="vp"></div>

Thank you very much.


Solution

  • Finally, I inserted HTML elements directly. This way I can create the form that I want, exactly as I want it.

    var myForm, formData;
    		var dhxWins, w1;
    		function doOnLoad() {
    			dhxWins = new dhtmlXWindows();
    			dhxWins.attachViewportTo("vp");
    			w1 = dhxWins.createWindow("w1", 10, 10, 300, 250);
    			myForm = w1.attachHTMLString(
          	'<div class="container">' +
            	'<div class="form-group col-xs-12 col-sm-6">' +
            		'<label>label</label>' +
                '<div>' +
                	'<input class="form-control" type="text">' +
                '</div>' +
              '</div>' +
            '</div>'
          );
    		}
    doOnLoad();
    div#vp {
    			height: 600px;
    			border: 1px solid #dfdfdf;
    		}
    <link rel="stylesheet" href="https://2a6781b6e7331b7c52c1706cd28c7de3f641b52b.googledrive.com/host/0B4bedT44-LokVFBFUXlaVEthaFE?t=.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
    <script src="https://ecropolis.s3.amazonaws.com/ui/libs/moment.min.js"></script>
    <script src="https://344bb70794e57c6753700eb885a1f4eb0c383612.googledrive.com/host/0B4bedT44-LokaV9tODJoX29BVFk"></script>
    
    <div id="vp"></div>