From fab87f7050355a6fb07fda70d2e3e82964470e2e Mon Sep 17 00:00:00 2001 From: "kevin.larke" Date: Tue, 28 Apr 2020 20:51:18 -0400 Subject: [PATCH] cwUi.cpp : Fixed bug where 'title' element type had the wrong type string. --- cwUi.cpp | 4 ++-- html/uiTest/js/ui.js | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cwUi.cpp b/cwUi.cpp index 7e31d7d..5534270 100644 --- a/cwUi.cpp +++ b/cwUi.cpp @@ -366,7 +366,7 @@ namespace cw // form the create json message string //unsigned i = snprintf( p->buf, p->bufN, "{ \"op\":\"create\", \"parent\":\"%s\", \"children\":{ \"%s\":{ \"eleName\":\"%s\", \"appId\":%i, \"uuId\":%i, \"class\":\"%s\", \"title\":\"%s\" ", parentEleName, eleTypeStr, eleName, appId, newEle->uuId, clas, title ); - unsigned i = snprintf( p->buf, p->bufN, "{ \"op\":\"create\", \"parentUuId\":\"%i\", \"type\":\"%s\", \"eleName\":\"%s\", \"appId\":\"%i\", \"uuId\":%i, \"className\":\"%s\", \"title\":\"%s\" ", parentEle->uuId, eleTypeStr, eleName==nullptr ? "" : eleName, appId, newEle->uuId, clas, title ); + unsigned i = snprintf( p->buf, p->bufN, "{ \"op\":\"create\", \"parentUuId\":\"%i\", \"type\":\"%s\", \"eleName\":\"%s\", \"appId\":\"%i\", \"uuId\":%i, \"className\":\"%s\", \"title\":\"%s\" ", parentEle->uuId, eleTypeStr, eleName==nullptr ? "" : eleName, appId, newEle->uuId, clas==nullptr ? " " : clas, title==nullptr ? " " : title ); // add the UI specific attributes @@ -1034,7 +1034,7 @@ cw::rc_t cw::ui::createDiv( handle_t h, unsigned& uuIdRef, unsigned wsSessId, un { return _createOneEle( _handleToPtr(h), uuIdRef, "div", wsSessId, parentUuId, eleName, appId, clas, title ); } cw::rc_t cw::ui::createTitle( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title ) -{ return _createOneEle( _handleToPtr(h), uuIdRef, "option", wsSessId, parentUuId, eleName, appId, clas, title ); } +{ return _createOneEle( _handleToPtr(h), uuIdRef, "title", wsSessId, parentUuId, eleName, appId, clas, title ); } cw::rc_t cw::ui::createButton( handle_t h, unsigned& uuIdRef, unsigned wsSessId, unsigned parentUuId, const char* eleName, unsigned appId, const char* clas, const char* title ) { return _createOneEle( _handleToPtr(h), uuIdRef, "button", wsSessId, parentUuId, eleName, appId, clas, title ); } diff --git a/html/uiTest/js/ui.js b/html/uiTest/js/ui.js index a4b6e62..8c6f8c4 100644 --- a/html/uiTest/js/ui.js +++ b/html/uiTest/js/ui.js @@ -310,11 +310,16 @@ function ui_create_ctl( parent_ele, ele_type, label, d, dfltEleClassName ) // if label is not null then create an enclosing 'label' element if( label != null ) { - label_ele = dom_create_ele("label"); + label = label.trim(); - label_ele.innerHTML = label; + if( label.length > 0) + { + label_ele = dom_create_ele("label"); - div_ele.appendChild(label_ele) + label_ele.innerHTML = label; + + div_ele.appendChild(label_ele) + } } return ui_create_ele( div_ele, ele_type, d, dfltEleClassName ); @@ -327,13 +332,18 @@ function ui_create_div( parent_ele, d ) if( div_ele != null ) { - if( d.title != null && d.title.length > 0 ) + if( d.title != null ) { - var p_ele = dom_create_ele("p") + var title = d.title.trim() + + if( title.length > 0 ) + { + var p_ele = dom_create_ele("p") - p_ele.innerHTML = d.title + p_ele.innerHTML = title - div_ele.appendChild( p_ele ) + div_ele.appendChild( p_ele ) + } } }