Skip to content

Commit

Permalink
added position & reposition param into calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Grand committed Jan 20, 2016
1 parent b4eb7f5 commit 0ccf10b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/nitro.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
-record(checkbox, {?ELEMENT_BASE(element_checkbox), autofocus, checked=false, disabled, form, name, required, value}).
-record(color, {?ELEMENT_BASE(element_color), autocomplete, autofocus, disabled, form, list, name, value}).
-record(date, {?ELEMENT_BASE(element_date), autocomplete, autofocus, disabled, form, list, max, min, name, step, readonly, required, value}).
-record(calendar, {?ELEMENT_BASE(element_calendar), autocomplete, autofocus, disabled, form, list, maxDate, minDate, format, name, step, readonly, required, value, placeholder, onSelect, disableDayFn}).
-record(calendar, {?ELEMENT_BASE(element_calendar), autocomplete, autofocus, disabled, form, list, maxDate, minDate, format, name, step, readonly, required, value, placeholder, onSelect, disableDayFn, position,reposition}).
-record(datetime, {?ELEMENT_BASE(element_datetime), autocomplete, autofocus, disabled, form, list, max, min, name, step, readonly, required, value}).
-record(datetime_local, {?ELEMENT_BASE(element_datetime_local), autocomplete, autofocus, disabled, form, list, max, min, name, step, readonly, required, value}).
-record(email, {?ELEMENT_BASE(element_email), autocomplete, autofocus, disabled, form, list, maxlength, multiple, name, pattern, placeholder, readonly, required, size, value}).
Expand Down
10 changes: 7 additions & 3 deletions src/elements/element_calendar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ render_element(Record) ->
],
wf_tags:emit_tag(<<"input">>, nitro:render(Record#calendar.body), List).

init(Id,#calendar{minDate=Min,maxDate=Max,lang=Lang,format=Form,value=Value,onSelect=SelectFn,disableDayFn=DisDayFn}) ->
init(Id,#calendar{minDate=Min,maxDate=Max,lang=Lang,format=Form,value=Value,onSelect=SelectFn,disableDayFn=DisDayFn, position=Pos,reposition=Repos}) ->
ID = nitro:to_list(Id),
I18n = case Lang of undefined -> "clLangs.ua"; Lang -> "clLangs."++nitro:to_list(Lang) end,
Format = case Form of undefined -> "YYYY-MM-DD"; Form -> Form end,
Expand All @@ -56,6 +56,8 @@ init(Id,#calendar{minDate=Min,maxDate=Max,lang=Lang,format=Form,value=Value,onSe
MaxDate = case Max of {Y1,M1,D1} -> nitro:f("new Date(~s,~s,~s)",[nitro:to_list(Y1),nitro:to_list(M1-1),nitro:to_list(D1)]); _ -> "new Date(2087, 4, 13)" end,
OnSelect = case SelectFn of undefined -> "null"; _ -> SelectFn end,
DisDay = case DisDayFn of undefined -> "null"; _ -> nitro:f("function(thisDate){return ~s(thisDate);}",[DisDayFn]) end,
Position = case Pos of undefined -> "bottom left"; _ -> nitro:to_list(Pos) end,
Reposition = case Repos of undefined -> "true"; _ -> nitro:to_list(Repos) end,
nitro:wire(nitro:f(
"pickers['~s'] = new Pikaday({
field: document.getElementById('~s'),
Expand All @@ -67,7 +69,9 @@ init(Id,#calendar{minDate=Min,maxDate=Max,lang=Lang,format=Form,value=Value,onSe
maxDate: ~s,
format: '~s',
onSelect: ~s,
disableDayFn: ~s
disableDayFn: ~s,
position: '~s',
reposition: ~s
});",
[ID,ID,I18n,DefaultDate,MinDate,MaxDate,Format,OnSelect,DisDay]
[ID,ID,I18n,DefaultDate,MinDate,MaxDate,Format,OnSelect,DisDay,Position,Reposition]
)).

0 comments on commit 0ccf10b

Please sign in to comment.