WebTextBox.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using FastReport.Dialog;
  2. using static FastReport.Web.Constants;
  3. namespace FastReport.Web
  4. {
  5. public partial class Dialog
  6. {
  7. private void TextBoxChange(TextBoxControl tb, string data)
  8. {
  9. tb.Text = data;
  10. tb.FilterData();
  11. tb.OnTextChanged(null);
  12. }
  13. private string GetValHook()
  14. {
  15. return
  16. "<script>$.valHooks.textarea = {" +
  17. "get: function(elem) {" +
  18. "return elem.value.replace(/\\r?\\n/g, \'\\r\\n\');" +
  19. "}};</script>";
  20. }
  21. private string GetTextBoxHtml(TextBoxControl control)
  22. {
  23. string id = GetControlID(control);
  24. string html;
  25. if (control.Multiline)
  26. {
  27. html = $"<textarea style=\"{GetTextBoxStyle(control)}\" type=\"text\" name=\"{control.Name}\"" +
  28. $" onchange=\"{GetEvent(ONCHANGE, control, DIALOG, $"document.getElementById('{id}').value.replace(/\\r?\\n/g, \'\\r\\n\')")}\"" +
  29. $" id=\"{id}\" maxlength=\"{control.MaxLength}\" {(control.Enabled ? "" : "disabled")}>{control.Text}</textarea>";
  30. }
  31. else
  32. {
  33. html = $"<input style=\"{GetTextBoxStyle(control)}\" type=\"text\" name=\"{control.Name}\" value=\"{control.Text}\"" +
  34. $" onchange=\"{GetEvent(ONCHANGE, control, DIALOG, $"document.getElementById('{id}').value")}\"" +
  35. $" id=\"{id}\" maxlength=\"{control.MaxLength}\" {(control.Enabled ? "" : "disabled")}/>";
  36. }
  37. return html;
  38. }
  39. private string GetTextBoxStyle(TextBoxControl control)
  40. {
  41. return $"{GetStandardStyle(control)} {GetControlAlign(control)}";
  42. }
  43. }
  44. }